16. Apr 2024, 14:47
VB-fun.de - Beitragsübersicht zum VB-/VBA-Forum-Archiv 0413
  VBS: Typen unverträglich: ’’
 Von  Inspirion
 Am  07. Oktober 2008 um 12:23:05
 Frage Hallo,

habe mir ein VBS script heruntergeladen welches aus einer
LOG Datei die Restlaufzeit des Akkus auslesen soll.

Bekomme leider immer folgende Fehlermeldung

[Error] Typen unverträglich: '[string: ", , "]'
In batmonread.vbs (LaptopTimeLeft)
Line 47, column 1


Hier mal das Script:
'########################################################
##################################
'# BATMONREAD.VBS [beta] For Samurize - (C) 2004 by
nashxgi - For free use - #
'# This script will retrieve the seconds remaining For
the systems #
'# battery Until it Is flat out of the logfile created by
the battery monitoring tool #
'# "Battery Monitor" from Passmark Corp. www.passmark.com
. #
'# INSTALL AND RUN IT BEFORE USING THIS SCRIPT !
#
'# The Function LaptopTimeLeft() will deliver 3 possible
stati To Samurize: #
'# 1- The expected leftover time In hrs:mins calculated
from the seconds measured #
'# 2- In Case Battery Monitor does Not deliver useful
data, Samurize gets a "No Status" #
'# message. This changes when data Is received again
from the BM-log. #
'# 3- In Case that leftover time Is less than 10 mins
the script will deliver a "Warning"#
'# message indicating that battery power Is very low.
#
'#
#
'# Setting the script:
#
'# 1- Set the current path To the BATTERY MON logfile In
Line 28. #
'# 2- If needed reset the MINS value For sending a
warning-message In Line 57. #
'########################################################
##################################

Option Explicit

Const ForReading = 1

Dim sFileName
Dim Feld(1)
Dim fso, oText
Dim i,std, min,y
Dim AnyString, MyStr,strTime
Dim bCreate

sFileName = "C:\Programme\Batterymon\batterymonlog.txt"
'// ADD PATH TO BATTERYMON LOG-FILE HERE
bCreate = False
i=0
Set fso = CreateObject("Scripting.FileSystemObject")
Set oText = fso.OpenTextFile(sFileName, ForReading,
bCreate)
Do Until oText.AtEndofStream
Feld(0)=oText.ReadLine
Feld(1)=Feld(0)
Loop
oText.Close

AnyString = Feld(1)
MyStr = Right(AnyString, 4)

If MyStr=", -1" Then
strTime="No Status"
Else
i=int(MyStr)
y=i/60
std=int(y/60)
min=y Mod 60
If std <> 0 Then
If min < 10 Then min = "0" & min
strTime = std& " : " & min & " left"
Else
strTime = std& " : " & min & " left"
If min < 10 Then '// SET THE
MINS-VALUE TO SEND A WARNING-MSG (Default Is 10)
strTime="W A R N I N G !"
End IF
End If
End If

Function LaptopTimeLeft()

LaptopTimeLeft=strTime

End Function
Auzug aus der Logdatei
2008-10-07, 10:50:54, OK, 30%, 4.58, 4951, 0, , 10.80, 0, 
30.0%, , , , , , , , , , , ,
 Antwort:
 Von Nepumuk
 eMail
 Am 07. Oktober 2008 um 15:54:22
 Antwort Hi,

na dann splitte doch einfach den String am Komma und benutze den "richtigen" Index des entstehenden Arrays. Voraussetzung ist natürlich, dass der gesuchte Eintrag immer an der selben Position steht.

Beispiel:
i="2008-10-07, 15:38:43, OK, 87%, 4.31, 13494, 0, , 10.80, 0, 87.0%, , , , , , , , , , , , "
msgbox split(i,",")(5)
Gruß
Nepumuk
[ VB-/VBA-Forum | Archiv 0413 | Archiv-Übersicht ]
 Antworten
VBS: Typen unverträglich: ’’ - Inspirion 07. Oktober 2008 um 12:23:05
Re: Typen unverträglich: ’’ - Nepumuk 07. Oktober 2008 um 15:03:27
Re: Typen unverträglich: ’’ - Inspirion 07. Oktober 2008 um 15:46:52
Re: Typen unverträglich: ’’ - Nepumuk 07. Oktober 2008 um 15:54:22
Re: Typen unverträglich: ’’ - Inspirion 07. Oktober 2008 um 19:17:40

Zum Seitenanfang

Startseite | VB-/VBA-Tipps | Projekte | Tutorials | API-Referenz | Komponenten | Bücherecke | Gewinnspiele | VB-/VBA-Forum | DirectX | DirectX-Forum | VB.Net | VB.Net-Forum | Chat | Spielplatz | Links | Suchen | Stichwortverzeichnis | Feedback | Impressum