User User name Password  
   
Wednesday 27.11.2024 / 17:39
Search AfterDawn Forums:        In English   Suomeksi   På svenska
afterdawn.com > forums > software, operating systems and more > windows - general discussion > vbs input box help
Show topics
 
Forums
Forums
vbs input box help
  Jump to:
 
Posted Message
bizkit101
Junior Member
_
19. October 2009 @ 15:58 _ Link to this message    Send private message to this user   
hi i made an input box that when you put the number of the program you want in it runs it that works. but i want to make the letter Q make it quit. i put in ElseIf

fname = Q Then
             WScript.Quit


But every time i put Q in, an error keeps coming up saying "type mismatch: '[string: "Q"]' " here is my whole code:

Dim fname

Sub Run(ByVal sFile)
Dim shell

    Set shell = CreateObject("WScript.Shell")
    shell.Run Chr(34) & sFile & Chr(34), 1, false
    Set shell = Nothing
End Sub

strMenu="Select a program" & VbCrLf &_
"1 HxD" & VbCrLf &_
"2 Johnson" & VbCrLf &_
"3 ConCept" & VbCrLf &_
"Q Quit"
do
fname=InputBox(strMenu,"Menu")

If fname = 1 Then
	Run "C:\Documents and Settings\fix\Local Settings\Application Data\HxD\HxD.exe"
ElseIf fname = 2 Then
	Run "C:\Documents and Settings\fix\My Documents\mods\programs\Johnson1.4_bin\Johnson.exe"
ElseIf fname = 3 Then
	Run "C:\Documents and Settings\fix\My Documents\mods\programs\CONcept 0.3\CONcept.exe"
ElseIf fname = Q Then
	WScript.Quit
END If
loop

I put The quit option in because i had to loop it so the input box wouldn't go away after it ran the program.

if you can give me an easier way to make the input box stay where it is please tell me but if you can't then just tell me whats wrong
thanks in advanced

This message has been edited since posting. Last time this message was edited on 20. October 2009 @ 17:01

Senior Member
_
21. October 2009 @ 19:55 _ Link to this message    Send private message to this user   
You're doing a mathematical comparison, that's why you're getting a type mismatch. The easiest solution is to simply change your quit option to a number, such as 4 or 999. If you really want to keep it a letter, then you need to make it mathematical for the program. Here's an option.
------------------------------------------------------
Dim fname

Sub Run(ByVal sFile)
Dim shell

Set shell = CreateObject("WScript.Shell")
shell.Run Chr(34) & sFile & Chr(34), 1, false
Set shell = Nothing
End Sub

strMenu="Select a program" & VbCrLf &_
"1 HxD" & VbCrLf &_
"2 Johnson" & VbCrLf &_
"3 ConCept" & VbCrLf &_
"Q Quit"
do
fname=InputBox(strMenu,"Menu")

if asc(fname) = 81 then
fname = 999
end if


If fname = 1 Then
Run "C:\Documents and Settings\fix\Local Settings\Application Data\HxD\HxD.exe"
ElseIf fname = 2 Then
Run "C:\Documents and Settings\fix\My Documents\mods\programs\Johnson1.4_bin\Johnson.exe"
ElseIf fname = 3 Then
Run "C:\Documents and Settings\fix\My Documents\mods\programs\CONcept 0.3\CONcept.exe"
ElseIf fname = 999 Then
WScript.Quit
END If
loop
------------------------------------------------------

The above code is case sensitive, so you will need to enter a capital Q. You could obviously edit it if you wanted to be able to use a lower case q.
afterdawn.com > forums > software, operating systems and more > windows - general discussion > vbs input box help
 

Digital video: AfterDawn.com | AfterDawn Forums
Music: MP3Lizard.com
Gaming: Blasteroids.com | Blasteroids Forums | Compare game prices
Software: Software downloads
Blogs: User profile pages
RSS feeds: AfterDawn.com News | Software updates | AfterDawn Forums
International: AfterDawn in Finnish | AfterDawn in Swedish | AfterDawn in Norwegian | download.fi
Navigate: Search | Site map
About us: About AfterDawn Ltd | Advertise on our sites | Rules, Restrictions, Legal disclaimer & Privacy policy
Contact us: Send feedback | Contact our media sales team
 
  © 1999-2024 by AfterDawn Ltd.

  IDG TechNetwork