Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 





Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read

Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
Thread Tools
Old 07-06-2008, 06:39 PM   #1 (permalink)
Registered User
 
Join Date: Jun 2008
Posts: 6
OS: WindowsXP


Thumbs Up Shorting code question

I like to try figuring how to shorten code before I resort to the last possibility, but I have had trouble with this one. Any insight into to shortening this would be appreciated :

Private Sub Timer1_Timer()
If VScroll1.Value = 0 Then


MSComm1.Output = "VOL00 " & Chr$(13)

ElseIf VScroll1.Value = 1 Then
MSComm1.Output = "VOL01 " & Chr$(13)

ElseIf VScroll1.Value = 2 Then
MSComm1.Output = "VOL02 " & Chr$(13)

ElseIf VScroll1.Value = 3 Then
MSComm1.Output = "VOL03 " & Chr$(13)

ElseIf VScroll1.Value = 4 Then
MSComm1.Output = "VOL04 " & Chr$(13)

ElseIf VScroll1.Value = 5 Then
MSComm1.Output = "VOL05 " & Chr$(13)

ElseIf VScroll1.Value = 6 Then
MSComm1.Output = "VOL06 " & Chr$(13)

ElseIf VScroll1.Value = 7 Then
MSComm1.Output = "VOL07 " & Chr$(13)

ElseIf VScroll1.Value = 8 Then
MSComm1.Output = "VOL08 " & Chr$(13)

ElseIf VScroll1.Value = 9 Then
MSComm1.Output = "VOL09 " & Chr$(13)

ElseIf VScroll1.Value = 10 Then
MSComm1.Output = "VOL10 " & Chr$(13)

ElseIf VScroll1.Value = 11 Then
MSComm1.Output = "VOL11 " & Chr$(13)

ElseIf VScroll1.Value = 12 Then
MSComm1.Output = "VOL12 " & Chr$(13)

ElseIf VScroll1.Value = 13 Then
MSComm1.Output = "VOL13 " & Chr$(13)

ElseIf VScroll1.Value = 14 Then
MSComm1.Output = "VOL14 " & Chr$(13)

ElseIf VScroll1.Value = 15 Then
MSComm1.Output = "VOL15 " & Chr$(13)

ElseIf VScroll1.Value = 16 Then
MSComm1.Output = "VOL16 " & Chr$(13)

ElseIf VScroll1.Value = 17 Then
MSComm1.Output = "VOL17 " & Chr$(13)

ElseIf VScroll1.Value = 18 Then
MSComm1.Output = "VOL18 " & Chr$(13)

ElseIf VScroll1.Value = 19 Then
MSComm1.Output = "VOL19 " & Chr$(13)

ElseIf VScroll1.Value = 20 Then
MSComm1.Output = "VOL20 " & Chr$(13)

ElseIf VScroll1.Value = 21 Then
MSComm1.Output = "VOL21 " & Chr$(13)

ElseIf VScroll1.Value = 22 Then
MSComm1.Output = "VOL22 " & Chr$(13)

ElseIf VScroll1.Value = 23 Then
MSComm1.Output = "VOL23 " & Chr$(13)

ElseIf VScroll1.Value = 24 Then
MSComm1.Output = "VOL24 " & Chr$(13)

ElseIf VScroll1.Value = 25 Then
MSComm1.Output = "VOL25 " & Chr$(13)

ElseIf VScroll1.Value = 26 Then
MSComm1.Output = "VOL26 " & Chr$(13)

ElseIf VScroll1.Value = 27 Then
MSComm1.Output = "VOL27 " & Chr$(13)

ElseIf VScroll1.Value = 28 Then
MSComm1.Output = "VOL28 " & Chr$(13)

ElseIf VScroll1.Value = 29 Then
MSComm1.Output = "VOL29 " & Chr$(13)

ElseIf VScroll1.Value = 30 Then
MSComm1.Output = "VOL30 " & Chr$(13)


Thanks
flyfish29 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 07-08-2008, 04:46 PM   #2 (permalink)
TSF Enthusiast
 
jamiemac2005's Avatar
 
Join Date: Jul 2007
Location: Northampton, UK
Posts: 910
OS: Win Vista Home Premium & Ubuntu Hardy(8.04)


Re: Shorting code question

Try:

Code:
MSComm1.Output = "VOL" & VScroll.Value & " " & Chr$(13)
If that doesn't work then use Switch Case Statements( sorry i'm unsure of how to do this in VB but google will help you)

Actually you will have to parse the VScroll.Value property if the number is <10 so maybe something like:

Code:
If VScroll1.Value < 10 Then
MSComm1.Output = "VOL0" & VScroll.Value & " " & Chr$(13)

Else
MSComm1.Output = "VOL" & VScroll.Value & " " & Chr$(13)
You may get an error saying the wrong datatype is being used(i can't remember how datatype handling is done in VB either), if that happens(you get something like datatype mismatch error) then look for an integer to string function (IntToStr()) then put VScroll.Value into it.... That's only if the above doesn't work

Cheers,
Jamey

Last edited by jamiemac2005 : 07-08-2008 at 04:47 PM. Reason: Missing code endtag
jamiemac2005 is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 07-09-2008, 06:15 PM   #3 (permalink)
Registered User
 
Join Date: Jun 2008
Posts: 6
OS: WindowsXP


Re: Shorting code question

Thanks, I have tried something like that....I dimmed a text and tried &'d, but it doesn't seem to work. I got it to work the long way, but I will try figuring it out a shorter way. Otherwise, I will just keep it how I got it. It seems to work well inside a timer with about a sec duration between the values. Thanks
flyfish29 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -7. The time now is 01:44 PM.



Copyright 2001 - 2008, Tech Support Forum

Search Engine Friendly URLs by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82