3 Replies - 1148 Views - Last Post: 16 October 2014 - 10:38 AM Rate Topic: -----

#1 Gian7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 15-September 11

How to fix Variable not defined?

Posted 15 October 2014 - 06:40 PM

It's my first time in doing a vb6 system and I'm trying to connect it to mysql database.
I followed this tutorial on youtube: https://www.youtube....h?v=lT2nxM1p4sg

But whenever I run the program, it pops-up "Variable Not Defined" on Private Sub Form_Load()

Option Explicit
Dim SData(24) As Byte
Dim SReply(48) As Byte
Dim Replied As Boolean
Dim rx As String
Dim CKS As Integer

Private Sub btnSave_Click()
Set rx = New ADODB.Recordset

rx.Open "select * from records", con, 3, 3

With rx
.AddNew
.Fields("empid") = txtwindow.Text
.Update
End With

MsgBox "New Data has been saved!"

Set rx = Nothing

End Sub

Private Sub cmdClear_Click()
Dim i As Integer
Dim dummy As String

For i = 1 To 22
    SData(i) = 0
Next i

SData(0) = &H55
SData(1) = &HAA
SData(2) = &H6
SData(3) = &H1
Call Checksum
Replied = False
dummy = MSComm1.Input
For i = 0 To 23
MSComm1.Output = Chr(SData(i))
Next i
While Replied = False
    DoEvents
    Wend
If SReply(6) = 0 Then
    txtResults.Text = "All Users deleted!"
Else
    txtResults.Text = "Error!"
End If
End Sub

Private Sub cmdRead_Click()
Dim i As Integer
Dim dummy As String
txtResults.Text = "Lagay mo daliri mo (isa lang!).."
  
For i = 1 To 22
    SData(i) = 0
Next i
SData(0) = &H55
SData(1) = &HAA
SData(2) = &H2
SData(3) = &H1
Call Checksum
dummy = MSComm1.Input
For i = 0 To 23
MSComm1.Output = Chr(SData(i))
Next i
back:
Replied = False
While Replied = False
    DoEvents
    Wend
If Asc(Mid$(Right$(rx, 24), 7, 1)) = 0 Then
    If Asc(Mid$(Right$(rx, 24), 9, 1)) = &HF4 And Asc(Mid$(Right$(rx, 24), 10, 1)) = &HFF Then
        GoTo back
    End If
    txtResults.Text = "Hello No. " + Str(Int(Asc(Mid$(Right$(rx, 24), 10, 1)) * 256 + Asc(Mid$(Right$(rx, 24), 9, 1)))) + "  Welcome!"
Else
    Print_Error
End If
    
End Sub

Private Sub cmdReg_Click()
Dim i As Integer
Dim dummy As String
Dim V1, V2 As Integer
Dim Good As Boolean

Good = True

V1 = Int(Val(txtUserNo.Text) / 256)
V2 = Val(txtUserNo.Text) - V1 * 256

For i = 1 To 22
    SData(i) = 0
Next i
SData(0) = &H55
SData(1) = &HAA
SData(2) = &H3
SData(3) = &H1
SData(4) = &H2
SData(5) = &H0
SData(6) = V2
SData(7) = V1
Call Checksum
dummy = MSComm1.Input
For i = 0 To 23
MSComm1.Output = Chr(SData(i))
Next i
back:
Replied = False
While Replied = False
    DoEvents
    Wend
If SReply(6) = 0 Then
    If Asc(Mid$(Right$(rx, 24), 9, 1)) = &HF1 And Asc(Mid$(Right$(rx, 24), 10, 1)) = &HFF Then
        txtResults.Text = "Press a finger to register first time."
    End If
    If Asc(Mid$(Right$(rx, 24), 9, 1)) = &HF2 And Asc(Mid$(Right$(rx, 24), 10, 1)) = &HFF Then
        txtResults.Text = "Press the same finger the second time..."
    End If
    If Asc(Mid$(Right$(rx, 24), 9, 1)) = &HF3 And Asc(Mid$(Right$(rx, 24), 10, 1)) = &HFF Then
        txtResults.Text = "Press the same finger the last time..."
    End If
    If Asc(Mid$(Right$(rx, 24), 9, 1)) = &HF4 And Asc(Mid$(Right$(rx, 24), 10, 1)) = &HFF Then
        txtResults.Text = "Lift finger..."
    End If
    If Asc(Mid$(Right$(rx, 24), 5, 1)) = &H6 Then
        txtResults.Text = "Ok"
        Exit Sub
    End If
    GoTo back
Else
    Print_Error
    If SReply(8) = &H21 Then GoTo back
    End If
End Sub

Private Sub cmdRemove_Click()
Dim i As Integer
Dim dummy As String
Dim V1, V2 As Integer

V1 = Int(Val(txtUserNo.Text) / 256)
V2 = Val(txtUserNo.Text) - V1 * 256

For i = 1 To 22
    SData(i) = 0
Next i

SData(0) = &H55
SData(1) = &HAA
SData(2) = &H5
SData(3) = &H1
SData(4) = &H2
SData(5) = &H0
SData(6) = V2
SData(7) = V1
Call Checksum
Replied = False
dummy = MSComm1.Input
For i = 0 To 23
MSComm1.Output = Chr(SData(i))
Next i
While Replied = False
    DoEvents
    Wend
If SReply(6) = 0 Then
    txtResults.Text = "User No. " + txtUserNo.Text + " Removed!"
Else
    txtResults.Text = "Error!"
End If

End Sub

Private Sub Command1_Click()
Dim i As Integer
Dim dummy As String
Dim V1, V2 As Integer

V1 = Int(Val(txtUserNo.Text) / 256)
V2 = Val(txtUserNo.Text) - V1 * 256

For i = 1 To 22
    SData(i) = 0
Next i

SData(0) = &H55
SData(1) = &HAA
SData(2) = &H4
SData(3) = &H1
SData(4) = &H2
SData(5) = &H0
SData(6) = V2
SData(7) = V1
Call Checksum
Replied = False
dummy = MSComm1.Input
For i = 0 To 23
MSComm1.Output = Chr(SData(i))
Next i
While Replied = False
    DoEvents
    Wend

End Sub

Private Sub Command2_Click()
Dim i As Integer
Dim dummy As String
Dim V1, V2 As Integer

V1 = Int(Val(txtUserNo.Text) / 256)
V2 = Val(txtUserNo.Text) - V1 * 256

For i = 1 To 22
    SData(i) = 0
Next i

SData(0) = &H55
SData(1) = &HAA
SData(2) = &H2
SData(3) = &H1
'SData(4) = &H2
'SData(6) = V1
'SData(7) = V2
Call Checksum
Replied = False
dummy = MSComm1.Input
For i = 0 To 23
MSComm1.Output = Chr(SData(i))
Next i
While Replied = False
    DoEvents
    Wend
End Sub

Private Sub Command3_Click()
Dim i As Integer
Dim dummy As String

For i = 1 To 22
    SData(i) = 0
Next i

SData(0) = &H55
SData(1) = &HAA
SData(2) = &H30
SData(3) = &H1
Call Checksum
Replied = False
dummy = MSComm1.Input
For i = 0 To 23
MSComm1.Output = Chr(SData(i))
Next i
While Replied = False
    DoEvents
    Wend
If SReply(6) = 0 Then
    txtResults.Text = "Cancelled!"
Else
    txtResults.Text = "Error!"
End If

End Sub

Private Sub Command4_Click()
    LED_On
End Sub

Private Sub Command5_Click()
    LED_Off
End Sub

Private Sub Form_Load()
Set Connect = New Class1
MSComm1.PortOpen = True
End Sub

Public Sub Checksum()
Dim i As Integer

CKS = 0
For i = 0 To 21
    CKS = CKS + SData(i)
Next i

SData(22) = CKS And &HFF
SData(23) = (CKS - (CKS And &HFF)) / 256

End Sub

Public Sub Finger_Detect()
Dim i As Integer
Dim dummy As String

wait_finger:
For i = 1 To 22
    SData(i) = 0
Next i
SData(0) = &H55
SData(1) = &HAA
SData(2) = &H13
SData(3) = &H1
Call Checksum
dummy = MSComm1.Input
For i = 0 To 23
MSComm1.Output = Chr(SData(i))
Next i
Replied = False
While Replied = False
    DoEvents
    Wend
If SReply(8) = 0 Then
    GoTo wait_finger
End If

End Sub

Public Sub LED_On()
Dim i As Integer
Dim dummy As String

For i = 1 To 22
    SData(i) = 0
Next i
SData(0) = &H55
SData(1) = &HAA
SData(2) = &H24
SData(3) = &H1
SData(4) = 2
SData(5) = 0
SData(6) = 1
Call Checksum
dummy = MSComm1.Input
For i = 0 To 23
MSComm1.Output = Chr(SData(i))
Next i
Replied = False
While Replied = False
    DoEvents
    Wend

End Sub

Public Sub LED_Off()
Dim i As Integer
Dim dummy As String

For i = 1 To 22
    SData(i) = 0
Next i
SData(0) = &H55
SData(1) = &HAA
SData(2) = &H24
SData(3) = &H1
SData(4) = 2
Call Checksum
dummy = MSComm1.Input
For i = 0 To 23
MSComm1.Output = Chr(SData(i))
Next i
Replied = False
While Replied = False
    DoEvents
    Wend
End Sub

Public Sub Print_Error()
    If Asc(Mid$(Right$(rx, 24), 9, 1)) = &H12 Then
        txtResults.Text = "Di kita kilala! Tsupi!"
    ElseIf Asc(Mid$(Right$(rx, 24), 9, 1)) = &H14 Then
        txtResults.Text = "Location not empty!"
    ElseIf Asc(Mid$(Right$(rx, 24), 9, 1)) = &H15 Then
        txtResults.Text = "No enrolled user!"
    ElseIf Asc(Mid$(Right$(rx, 24), 9, 1)) = &H21 Then
        txtResults.Text = "Bad quality fingerprint image!"
    ElseIf Asc(Mid$(Right$(rx, 24), 9, 1)) = &H60 Then
        txtResults.Text = "Location No. not valid!"
    End If
End Sub

Private Sub MSComm1_OnComm()
Dim RxNumeric As String
Dim i As Integer

rx = MSComm1.Input
RxNumeric = ""
For i = 1 To Len(rx)
SReply(i - 1) = Asc(Mid(rx, i, 1))
RxNumeric = RxNumeric + " " + Hex(SReply(i - 1))
Next i
txtwindow.Text = RxNumeric
Replied = True
End Sub

Private Sub Timer1_Timer()
    Timer1.Enabled = False
End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: How to fix Variable not defined?

#2 andrewsw  Icon User is online

  • say what now
  • member icon

Reputation: 6407
  • View blog
  • Posts: 25,884
  • Joined: 12-December 12

Re: How to fix Variable not defined?

Posted 15 October 2014 - 11:46 PM

Which variable(s) does it say you haven't defined? Post the full error message.

But in your Form_Load you only have two variables, Connect and MsComm1, neither of which you have declared.

BTW Why are you starting with VB6 which is ancient and unsupported?
Was This Post Helpful? 0
  • +
  • -

#3 Gian7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 15-September 11

Re: How to fix Variable not defined?

Posted 16 October 2014 - 10:30 AM

Posted Image


Here are my classes, just the way I followed from the tutorial.
I'm still using this because the biometrics (finger scanner) doesn't work (or can't be detected on my w8.1) as well as that I can't convert
these to vb.net (2012/2013), doesn't work. This is just a school project by the way. I just want to store user's sign-in and sign-out using the biometrics. :)


Class1:
Private Sub class_initialize()
DoEvents
Set con = New ADODB.Connection
With con
.ConnectionString = "Driver=(MySQL ODBC 3.51 Driver);SERVER=localhost;PWD=;UID=root;PORT=3306;DATABASE=biometrics;"
.CursorLocation = adUseClient
.Open
End With
End Sub



Module1:
Public con As New ADODB.Connection
Public rx As New ADODB.Recordset
Public rxd As New ADODB.Recordset


Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • say what now
  • member icon

Reputation: 6407
  • View blog
  • Posts: 25,884
  • Joined: 12-December 12

Re: How to fix Variable not defined?

Posted 16 October 2014 - 10:38 AM

Yes, Connect is not defined. Somewhere you should have code:
Dim Connect As Class1    'BTW Class1 is a terrible name

Maybe this code should be in Module1, but I'm just guessing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1