Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I NEED SOME HELP WITH THIS CODE (VB6)

Status
Not open for further replies.

compcad

Programmer
Mar 22, 2002
52
0
0
US
part A

I am designing a back end to a program a client has on his computer. I
have completed the back end and it works fine but(not with the front end
thow.) The area that I need the help is to get my back end to work with
the code he has provided to me. Here is the code he has provided me with.



Code:
Sub ParseCommandLine(CmdLine, RaffielD, Password, FirstTicketNo,
LastTicketNo)
‘There will be either 3 or 4 parameters
‘If there are only 3 then the third is last ticket no and a first ticket
no of 1 is implied
‘If there are 4 then the third is first ticket no and the fourth is last
ticket no
‘The first 2 args are always password and RaffielD

Password = GetNextArgument(CmdLine)
RaffielD = GetNextArgument(CmdLine)
FirstTicketNo = GetNextArgument(CmdLine)
LastTicketNo = GetNextArgument(CmdLine)

If LastTicketNo = "" Then
LastTicketNo = FirstTicketNo
FirstTicketNo = 1
End If

End Sub
Function GetNextArgument(CmdLine)

Index = InStr(CmdLine, " ")
If (Index = 0) Then
'End of line
GetNextArgument = CmdLine
GetNextArgument = Replace(CmdLine, """", "")
'Remove double quotes
CmdLine = ""
Exit Function
End If
GetNextArgument = Left(CmdLine, Index)
GetNextArgument = Replace(GetNextArgument, """", "") 'Remove double quotes
CmdLine = Right(CmdLine, Len(CmdLine) - Index)
End Function

I need help reading this code such as where it says:



Code:
'Remove double quotes

Does that mean the double quotes are within his main code and this
function will remove them as they are being passed through this function
and into my back end or should the double quotes be in my code and the
function will take care of things. I may have some more questions about
this code but I will start with this much. I would like to get this behind
me. If you could give me any help it would be greatful.

p.s.: If you need any more information I will provide it

Thank You

part B

I had designed a small app to test out the code I had originally posted to
this thread.:
I took a form and put some textboxs and a couple of command buttons. I am
only going to talk about one of the command buttons because they do the
same thing. In command button 1 I put the following code from the above
thread.



Code:
Sub ParseCommandLine(CmdLine, RaffielD, Password, FirstTicketNo,
LastTicketNo)
‘There will be either 3 or 4 parameters
‘If there are only 3 then the third is last ticket no and a first ticket
no of 1 is implied
‘If there are 4 then the third is first ticket no and the fourth is last
ticket no
‘The first 2 args are always password and RaffielD
Password = GetNextArgument(CmdLine)
RaffielD = GetNextArgument(CmdLine)
FirstTicketNo = GetNextArgument(CmdLine)
LastTicketNo = GetNextArgument(CmdLine)

If LastTicketNo = "" Then
LastTicketNo = FirstTicketNo
FirstTicketNo = 1
End If

End Sub
Function GetNextArgument(CmdLine)

Index = InStr(CmdLine, " ")
If (Index = 0) Then
'End of line
GetNextArgument = CmdLine
GetNextArgument = Replace(CmdLine, """", "") 'Remove double quotes
CmdLine = ""
Exit Function
End If
GetNextArgument = Left(CmdLine, Index)
GetNextArgument = Replace(GetNextArgument, """", "") 'Remove double quotes
CmdLine = Right(CmdLine, Len(CmdLine) - Index)
End Function


I then added the following lines of code to the bottom of this code above
in the same command button.



Code:
Private Sub Command1_Click()
Call ParseCommandLine (CmdLine, RaffleID, Password, FirstTicketNo,
LastTicketNo)
Dim cCommand as String

cCommand="C:\Program Files\RaffleMaker\RMDESKTOP\TB - LITE.EXE " & _
CmdLine & ", " & RaffleID & ", " & Password & ", " & FirstTicketNo & ", "
& LastTicketNo
RetVal = Shell (cCommand, 1)
End Sub


I tested the app out by clicking on run I put a value into each of the
textboxs in the small app and then I pressed one of the command buttons
that has this code in it and then my backend did open as it was designed
to. The only thing is I cannot add this code to the clients program.

If you need any more information I will provide it.

Thank You

part C

Is there a way to use the code that I had showed in the last two replys
without using this code as show in this reply.




Code:
Private Sub Command1_Click()
Call ParseCommandLine (CmdLine, RaffleID, Password, FirstTicketNo,
LastTicketNo)
Dim cCommand as String

cCommand="C:\Program Files\RaffleMaker\RMDESKTOP\TB - LITE.EXE " & _
CmdLine & ", " & RaffleID & ", " & Password & ", " & FirstTicketNo & ", "
& LastTicketNo
RetVal = Shell (cCommand, 1)
End Sub

or do you think this maybe the best way to go. To get the two programs to
work together.

I need help on this project as soon as possible. I would like to get this
behind me.

Thank You

part D

I had entered this code into the back end I am trying to create. The small
application I built that is located in my last reply works fine but when I
try it on the clients appliction it does not seem to work and so it seems
to be a problem with passing the parameters. If anyone has any ideas could
you please help me. If you do not understand what I am trying to get
across I could try to send more information. It is hard when he will not
let me test it except when he is around with the program.

THANK YOU


Code:
Private Sub Form_Activate()

Dim strValuesFromCommandLine() As String
Dim CmdLine As String
Dim RAFFLEID As String
Dim PASSWORD As String
Dim FirstTicketNo As String
Dim LastTicketNo As String
Dim RAFFLEID1a As String

Forml.WindowState = 0

If Len (Command) > 0 Then
strValuesFromCommandLine() = Split(Command$, ", ")
CmdLine = strValuesFromCommandLine(0)
RAFFLEID = strValuesFromCommandLine(1)
PASSWORD = strValuesFromCommandLine(2)
FirstTicketNo = strValuesFromCommandLine(3)
LastTicketNo = strValuesFromCommandLine(4)
Else
MsgBox "Stand alone is not supported by this program.", vbOKOnly
End
End If
.
.
.
End Sub
 
Well this is a lot of stuff.

How about I reformat Part A and add a few comments.

This will help you see what is going on.
Code:
Sub ParseCommandLine(CmdLine, RaffielD, Password, FirstTicketNo, LastTicketNo)
	'The first 2 args are always password and RaffielD
	Password = GetNextArgument(CmdLine)
	RaffielD = GetNextArgument(CmdLine)
	
	
	'There will be either 3 or 4 parameters
	'
	'If there are 4 then the third is first ticket no and the fourth is last
	'ticket no 
	FirstTicketNo = GetNextArgument(CmdLine)
	LastTicketNo = GetNextArgument(CmdLine)

	If LastTicketNo = "" Then
		'If there are only 3 then the third is last ticket no and a first ticket
		'no of 1 is implied
		LastTicketNo = FirstTicketNo
		FirstTicketNo = 1
	End If
End Sub

Function GetNextArgument(CmdLine)
	'Find position of next 'space' character in CmdLine
	Index = InStr(CmdLine, " ")
	
	'If no 'space' character was found...
	If (Index = 0) Then 
		'End of line
		'Only 1 parameter remains in CmdLine so the entire value of
		'CmdLine is used for the return value of GetNextArgument.
		
		'Remove double quotes from GetNextArgument return value
		GetNextArgument = Replace(CmdLine, """", "")
		
		'This was the last parameter in CmdLine so set it to empty string
		CmdLine = ""
		Exit Function
	End If

	'Put all characters up to the 'space' into GetNextArgument return value
	GetNextArgument = Left(CmdLine, Index)
	
	'Remove double quotes from GetNextArgument return value
	GetNextArgument = Replace(GetNextArgument, """", "") 
	
	'Shave off the part of CmdLine that we just put into return value
	CmdLine = Right(CmdLine, Len(CmdLine) - Index)
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top