• Welcome to SQLitening Support Forum.
 

VB6 could use same calls as PowerBASIC by not using BYVAL with strings.

Started by cj, October 15, 2011, 05:54:51 PM

Previous topic - Next topic

cj

1) If BYVAL is removed from calls with strings then VB6 could use the same calls as PowerBASIC.
Example:

FUNCTION slConnect ALIAS "slConnect" (OPTIONAL rsServerTemp AS STRING, _
                                      OPTIONAL BYVAL rlPort AS LONG, _
                                      OPTIONAL rsModChars AS STRING, _
                                      OPTIONAL wsOutData AS STRING)Export AS LONG
    LOCAL rsServer AS STRING
    rsServer = rsServerTemp         
END FUNCTION


Trival, but while testing with VB6 found this:
If a connection fails
result = slGetFile(sFile,sData,"E1") will terminate program
One solution is to just use slSetProcessMods "E1"

Passing a nul or "" instead of using OPTIONAL would not be a problem for me.
I actually prefer it because then the options are always right there.

With the modication to Sqlitening.Bas in slConnect above this works fine with VB6.
This eliminates the need for SQLiteningS.dll  with this little VB6 test program.

Declare Function slGetFile Lib "SQLitening.Dll" (ByRef rsFileName As String, ByRef wsFileData As String, Optional ByRef rsModChars As String) As Long
Declare Function slConnect Lib "SQLitening.Dll" (Optional rsServer As String, Optional ByVal rlPort As Long, Optional ByRef rsModChars As String, Optional ByRef wsDataOut As String) As Long
Declare Sub slDisconnect Lib "SQLitening.Dll" ()
Sub Main()
  result& = slConnect("192.168.1.2", 51234)
  result& = slGetFile("RemoteFileUploadDownloadExample.txt", sData$)
  slDisconnect
  MsgBox Str$(Len(sData$)) + " bytes"
End Sub


A more complete VB6 example handling all errors without terminating in environment
Requires SQLitening.DLL and SQLiteningClient.DLL


Option Explicit '#DIM ALL in PowerBASIC
'Sqlitening declares
Declare Sub slSetProcessMods Lib "SQLitening.Dll" (ByRef rsModChars As String)
Declare Function slGetFile Lib "SQLitening.Dll" (ByRef rsFileName As String, ByRef wsFileData As String, Optional ByRef rsModChars As String) As Long
Declare Function slConnect Lib "SQLitening.Dll" (Optional rsServer As String, Optional ByVal rlPort As Long, Optional ByRef rsModChars As String, Optional ByRef wsDataOut As String) As Long
Declare Sub slDisconnect Lib "SQLitening.Dll" ()
Declare Function slGetError Lib "SQLitening.Dll" () As String
Declare Sub apiSleep Lib "KERNEL32.DLL" Alias "Sleep" (ByVal Milliseconds As Long)
'Constants to download
Const Ip As String = "192.168.1.2"  'Change 1 of 2
Const PortNumber As Long = 51234    'Change 2 of 2
Const sFile      As String = "RemoteFileUploadDownloadExample.txt"
'Main entry point
Sub Main()
  ReadFileOnServer
End Sub
Sub ReadFileOnServer()
  On Error Resume Next                 'an invalid might be returned by chdir
  Dim sData As String, result As Long  'define variables
  ChDir App.Path                       'useful if program in a temp folder or using VB6 environment
  slSetProcessMods "E0"                'E0=do not allow ExitProcess to terminate VB6 environment
  result = slConnect(Ip, PortNumber)   'attempt connection on local ip,  0=success
  If result = 0 Then                   'success
    result = slGetFile(sFile, sData$)  'attempt getting file, 0=success
    If result = 0 Then                 'success
      MsgBox Format$(Len(sData), "##,###,###,### bytes returned.") 'display bytes returned
    Else                               '
      MsgBox slGetError                'error, unable to get file
    End If                              '
    slDisconnect                       'disconnect if we connected
  Else                                 '
    MsgBox slGetError                  'error, unable to connect
  End If
End Sub








"No email alerts being received"  Please often check back.

cj

#1
Fred,
Hope you consider this method so the same code is shared with PB and VB.


#IF 0
FUNCTION slConnect ALIAS "slConnect" (OPTIONAL BYVAL rsServer AS STRING, _
                                      OPTIONAL BYVAL rlPort AS LONG, _
                                      OPTIONAL BYVAL rsModChars AS STRING, _
                                      OPTIONAL wsOutData AS STRING)EXPORT AS LONG
#ENDIF

FUNCTION slConnect ALIAS "slConnect" (OPTIONAL rsServerTemp     AS STRING, _
                                      OPTIONAL BYVAL rlPort     AS LONG, _
                                      OPTIONAL rsModCharsTemp   AS STRING, _
                                      OPTIONAL wsOutDataTemp    AS STRING) EXPORT AS LONG

  LOCAL rsServer,rsModChars,wsOutData AS STRING
  IF VARPTR(rsServerTemp)   THEN rsServer    = rsServerTemp
  IF VARPTR(rsModCharsTemp) THEN rsModChars  = rsModCharsTemp
  IF VARPTR(wsOutDataTemp)  THEN wsOutData   = wsOutDataTemp
.
.
   ' Set returning data
      REM IF ISFALSE ISMISSING(wsOutData) THEN wsOutData = lsA
      wsOutData = lsA
   
                                                                     
"No email alerts being received"  Please often check back.

Fred Meier

The same code is shared now.  The Special and Universal API's are just shells (front-ends) to the Basic API.

cj

It was only a suggestion to use the same include files and dll files.
SQLiteningS.Inc and SQLiteningS.dll would not be needed with VB6.


"No email alerts being received"  Please often check back.

Fred Meier

It would be a good idea if starting over.  SQLitening.Bas is actually a port from my personal PB SQLite interface so VB nor .Net was never considered at the beginning.

cj

I hear ya.  If anyone is interested, I will add them and put into a separate file.
I don't want to modify the original source to cause any problem when updating.
I have been running non-stop for days and have never seen the server lockup.
I would make some suggestions, but for security reasons will not do them here.
"No email alerts being received"  Please often check back.

D. Wilson

I use SQLitening with VB6. I have adopted it as the database engine for several programs that are in use today. The users liked the interface so it was not a bad conversion to convert from Tsumani to SQLitening. I have also upgraded these programs when new versions have been published. I would HATE to see the support for VB6 disappear. Just my thoughts.

Fred Meier

There is no plan to stop supporting VB.  CJ was just exploring a better way it could have been supported.  The Special and Universal API will remain as is.