Ciprian Pavel
April 19th, 2001, 02:05 AM
What is wrong with my code:
The problem is that:
-when I run my program after a connection has been served it crashes but when I run it with F8 it works very fine.
Dim IndexClient as Long
Dim TotalClients as Long
Dim Connection as new ADODB.Connection
Dim Command as new ADODB.Command
Dim Recordset(20) as new ADODB.Recordset
private Sub Form_Load()
Clients.Clear
Connection.Open "DSN=Oracle;UID=userid;PWD=password"
Server(0).Listen
for i = 1 to 20
Load Server(i)
next i
End Sub
private Sub Form_Unload(Cancel as Integer)
If Connection.State <> adStateClosed then
Connection.Close
End If
Clients.Clear
for i = 1 to IndexClient
If Server(i).State <> sckClosed then
Server(i).Close
Unload Server(i)
End If
next i
End Sub
private Sub Server_Close(Index as Integer)
'un client se deconecteaza si trebuie sa-l sterg din lista
Server(Index).Close
Clients.Clear
for i = 1 to 20
If Server(i).State <> sckClosed then
Clients.AddItem Server(i).RemoteHostIP
End If
next i
IndexClient = IndexClient - 1
End Sub
private Sub Server_ConnectionRequest(Index as Integer, byval requestID as Long)
TotalClients = TotalClients + 1
Total = "Total clients: " & TotalClients
'se conecteaza un client
IndexClient = IndexClient + 1
for i = 1 to IndexClient
If Server(i).State = sckClosed then
Server(i).LocalPort = 0
Server(i).Accept requestID
Exit for
End If
next i
'If i = IndexClient then
' Server(IndexClient).LocalPort = 0
' Server(IndexClient).Accept requestID
'End If
Clients.AddItem Server(IndexClient).RemoteHostIP
End Sub
private Sub Server_DataArrival(Index as Integer, byval bytesTotal as Long)
'un client cere date trimitand un string
'analizez stringul si ii trimit datele sau eroare
Dim Data as string
Dim mumu 'nu stiu de ce
Server(Index).GetData Data
If IsNumeric(Data) = true then
'stringul trimis este cod de articol sau cod de bare
mumu = Cod_Articol(Index, Data)
else
'stringul trimis este denumire de articol;ex: coca-cola
mumu = Denumire_Articol(Index, Data)
End If
End Sub
private Function Cod_Articol(byval Index as Integer, byval CodArticol as string)
CodArticol = Trim(CodArticol)
Command.ActiveConnection = Connection
If len(CodArticol) = 8 And mid(CodArticol, 1, 1) = "2" then
CodArticol = mid(CodArticol, 2, 6)
End If
If len(CodArticol) > 8 And mid(CodArticol, 1, 2) = "28" then
Command.CommandText = "select art_no from barcode where barcode like " & mid(CodArticol, 1, 7)
Recordset(Index).Open Command, , adOpenStatic, adLockOptimistic, adCmdText
If Recordset(Index).RecordCount >= 0 then
CodArticol = Recordset(Index).Fields(0)
else
Server(Index).SendData "ERR"
GoTo sfarsit
End If
End If
If len(CodArticol) > 8 then 'este cod de bare normal
Command.CommandText = "select art_no from barcode where barcode like " & CodArticol
Recordset(Index).Open Command, , adOpenStatic, adLockOptimistic, adCmdText
If Recordset(Index).RecordCount >= 0 then
CodArticol = Recordset(Index).Fields(0)
else
Server(Index).SendData "ERR"
GoTo sfarsit
End If
End If
If Recordset(Index).State <> adStateClosed then
Recordset(Index).Close
End If
Command.CommandText = "select * from cioprica_symbol where art_no=" & CodArticol
Recordset(Index).Open Command, , adOpenStatic, adLockOptimistic, adCmdText
If Recordset(Index).RecordCount > 0 then
for i = 0 to 15
Server(Index).SendData Recordset(Index).Fields(i) & "@"
next i
else
Server(Index).SendData "ERR"
End If
sfarsit:
Recordset(Index).Close
End Function
public Function Denumire_Articol(byval Index as Integer, byval DenArticol as string)
Command.ActiveConnection = Connection
DenArticol = UCase(DenArticol)
Command.CommandText = "select art_no,descr from article where descr like '%" & Trim(DenArticol) & "%'"
Recordset(Index).Open Command, , adOpenStatic, adLockOptimistic, adCmdText
If Recordset(Index).RecordCount > 0 And Recordset(Index).RecordCount <= 50 then
Recordset(Index).MoveFirst
for i = 1 to Recordset(Index).RecordCount
Server(Index).SendData Recordset(Index).Fields(0) & "@" & Recordset(Index).Fields(1) & "@"
Recordset(Index).MoveNext
next i
else
If Recordset(Index).RecordCount > 50 then
Server(Index).SendData "SPC"
else
Server(Index).SendData "ERR"
End If
End If
Recordset(Index).Close
End Function
Thanks
The problem is that:
-when I run my program after a connection has been served it crashes but when I run it with F8 it works very fine.
Dim IndexClient as Long
Dim TotalClients as Long
Dim Connection as new ADODB.Connection
Dim Command as new ADODB.Command
Dim Recordset(20) as new ADODB.Recordset
private Sub Form_Load()
Clients.Clear
Connection.Open "DSN=Oracle;UID=userid;PWD=password"
Server(0).Listen
for i = 1 to 20
Load Server(i)
next i
End Sub
private Sub Form_Unload(Cancel as Integer)
If Connection.State <> adStateClosed then
Connection.Close
End If
Clients.Clear
for i = 1 to IndexClient
If Server(i).State <> sckClosed then
Server(i).Close
Unload Server(i)
End If
next i
End Sub
private Sub Server_Close(Index as Integer)
'un client se deconecteaza si trebuie sa-l sterg din lista
Server(Index).Close
Clients.Clear
for i = 1 to 20
If Server(i).State <> sckClosed then
Clients.AddItem Server(i).RemoteHostIP
End If
next i
IndexClient = IndexClient - 1
End Sub
private Sub Server_ConnectionRequest(Index as Integer, byval requestID as Long)
TotalClients = TotalClients + 1
Total = "Total clients: " & TotalClients
'se conecteaza un client
IndexClient = IndexClient + 1
for i = 1 to IndexClient
If Server(i).State = sckClosed then
Server(i).LocalPort = 0
Server(i).Accept requestID
Exit for
End If
next i
'If i = IndexClient then
' Server(IndexClient).LocalPort = 0
' Server(IndexClient).Accept requestID
'End If
Clients.AddItem Server(IndexClient).RemoteHostIP
End Sub
private Sub Server_DataArrival(Index as Integer, byval bytesTotal as Long)
'un client cere date trimitand un string
'analizez stringul si ii trimit datele sau eroare
Dim Data as string
Dim mumu 'nu stiu de ce
Server(Index).GetData Data
If IsNumeric(Data) = true then
'stringul trimis este cod de articol sau cod de bare
mumu = Cod_Articol(Index, Data)
else
'stringul trimis este denumire de articol;ex: coca-cola
mumu = Denumire_Articol(Index, Data)
End If
End Sub
private Function Cod_Articol(byval Index as Integer, byval CodArticol as string)
CodArticol = Trim(CodArticol)
Command.ActiveConnection = Connection
If len(CodArticol) = 8 And mid(CodArticol, 1, 1) = "2" then
CodArticol = mid(CodArticol, 2, 6)
End If
If len(CodArticol) > 8 And mid(CodArticol, 1, 2) = "28" then
Command.CommandText = "select art_no from barcode where barcode like " & mid(CodArticol, 1, 7)
Recordset(Index).Open Command, , adOpenStatic, adLockOptimistic, adCmdText
If Recordset(Index).RecordCount >= 0 then
CodArticol = Recordset(Index).Fields(0)
else
Server(Index).SendData "ERR"
GoTo sfarsit
End If
End If
If len(CodArticol) > 8 then 'este cod de bare normal
Command.CommandText = "select art_no from barcode where barcode like " & CodArticol
Recordset(Index).Open Command, , adOpenStatic, adLockOptimistic, adCmdText
If Recordset(Index).RecordCount >= 0 then
CodArticol = Recordset(Index).Fields(0)
else
Server(Index).SendData "ERR"
GoTo sfarsit
End If
End If
If Recordset(Index).State <> adStateClosed then
Recordset(Index).Close
End If
Command.CommandText = "select * from cioprica_symbol where art_no=" & CodArticol
Recordset(Index).Open Command, , adOpenStatic, adLockOptimistic, adCmdText
If Recordset(Index).RecordCount > 0 then
for i = 0 to 15
Server(Index).SendData Recordset(Index).Fields(i) & "@"
next i
else
Server(Index).SendData "ERR"
End If
sfarsit:
Recordset(Index).Close
End Function
public Function Denumire_Articol(byval Index as Integer, byval DenArticol as string)
Command.ActiveConnection = Connection
DenArticol = UCase(DenArticol)
Command.CommandText = "select art_no,descr from article where descr like '%" & Trim(DenArticol) & "%'"
Recordset(Index).Open Command, , adOpenStatic, adLockOptimistic, adCmdText
If Recordset(Index).RecordCount > 0 And Recordset(Index).RecordCount <= 50 then
Recordset(Index).MoveFirst
for i = 1 to Recordset(Index).RecordCount
Server(Index).SendData Recordset(Index).Fields(0) & "@" & Recordset(Index).Fields(1) & "@"
Recordset(Index).MoveNext
next i
else
If Recordset(Index).RecordCount > 50 then
Server(Index).SendData "SPC"
else
Server(Index).SendData "ERR"
End If
End If
Recordset(Index).Close
End Function
Thanks