-
Code:
Dim Output
Dim intnum As Long
Dim x
Public Function FileExists(FullName As String) As Boolean
FileExists = Len(Dir(FullName))
End Function
Private Sub Form_Load()
If FileExists("C:\a.dat") Then
Dim strItem4 As String
Open "c:\a.dat" For Input As #1
Input #1, strItem1
Close #1
Label1.Caption = strItem1
'***********************************************************************************************************************
'***********************************************************************************************************************
intnum = CInt(strItem1) 'I always get a type DisMatch Error Here can Someone Please tell me what I am doing wrong
'***********************************************************************************************************************
'***********************************************************************************************************************
intnum = intnum + 1
Label1.Caption = CStr(intnum)
Open "c:\a.dat" For Output As #1
Print #1, Label1.Caption
Close #1
ProgressBar1.Value = Label1.Caption
Label4.Caption = 100 - Label1.Caption
Else:
Label1.Caption = "1"
Open "c:\a.dat" For Output As #1
Print #1, Label1.Caption
Close #1
ProgressBar1.Value = Label1.Caption
Label4.Caption = 100 - Label1.Caption
End If
End Sub
Private Sub Label1_Change()
If Label1.Caption = "100" Then
Open "C:\a.dat" For Output As #1
Print #1, "100"
Close #1
End
End If
End Sub
-
Chances are whatever is in strItem1 is not a number. Try doing this
if IsNumeric(strItem1) then _
intnum = CInt(strItem1)
see what happens
Cthulhu Dragon
-
-
Did you try using the CLng function instead of CInt? I wouldn't imagine it would make much difference, but you never know.
-
<?>
Dim strItem4 As String
Open "c:\a.dat" For Input As #1
Input #1, strItem1
Close #1
Label1.Caption = strItem1
try
stritem1 = Cint(stritem)
intnum = strItem1)
-
Quote:
Originally posted by dimava
Code:
Dim Output
Dim intnum As Long
Dim x
'<<<< Here I would remove this function entirely..seems
'a waste of code to me...>>>>
Public Function FileExists(FullName As String) As Boolean
FileExists = Len(Dir(FullName))
End Function
Private Sub Form_Load()
'<<<< Here you can simply say:
' If Dir("C:\a.dat") <> "" Then >>>>
If FileExists("C:\a.dat") Then
Dim strItem4 As String
Open "c:\a.dat" For Input As #1
Input #1, strItem1
Close #1
Label1.Caption = strItem1
'<<<< Can you see label1 change before it gives you
'the error? If not put a:
'Debug.print strItem1
'and make sure its giving you a value>>>>
'<<<<And lastly... Cint takes a variant and turns it into a 'Integer, but you declare strItem1 as a string, try using:
'intnum = Int(strItem1)
'Instead, that takes an integer from a string..>>>>>
'***********************************************************
intnum = CInt(strItem1) 'I always get a type DisMatch Error Here can Someone Please tell me what I am doing wrong
'***********************************************************
intnum = intnum + 1
Label1.Caption = CStr(intnum)
Open "c:\a.dat" For Output As #1
Print #1, Label1.Caption
Close #1
ProgressBar1.Value = Label1.Caption
Label4.Caption = 100 - Label1.Caption
Else:
Label1.Caption = "1"
Open "c:\a.dat" For Output As #1
Print #1, Label1.Caption
Close #1
ProgressBar1.Value = Label1.Caption
Label4.Caption = 100 - Label1.Caption
End If
End Sub
Private Sub Label1_Change()
If Label1.Caption = "100" Then
Open "C:\a.dat" For Output As #1
Print #1, "100"
Close #1
End
End If
End Sub
'Hope this helps!!
-
It may be a number but a number is not always a number...if a number is a "1" then it's concidered a string and VB tends to flip out.. however if it's just a 1 then it's a number...Part of it is because + can be used the same as &
Example:
"1" + "1"=11
1+1=2
1 x 1=1
"1" x "1"=Mismatch... cuz you can't multiply a text string times a text string.
Eiredrake
-
<?>
Actually, Dimava, I cut and pasted your code and it
runs just fine...no errors...perhaps you need to
check the contents of your file.
If when you write to the file you use the
Write #1, mydata
you will get "4"
If you use the
Print#1, mydata
you will get a 4
[Edited by HeSaidJoe on 07-27-2000 at 03:15 PM]
-
I found my error, it was this 1 huge mistake that I made, but everything works fin now, thanks for all your help
-
Hate to be picky, Dimava, but:
1 - 1 = 0
1 % 1 = 0.01
I'm sure if you take extra maths classes, you'll cope just fine.
-
Yea I know but that what they teached us in 7th grade (its a joke)