Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,740,606 Members 47,747 Now Online
XDA Developers Android and Mobile Development Forum

help VB

Tip us?
 
fujirio
Old
#1  
Senior Member - OP
Thanks Meter 23
Posts: 171
Join Date: Feb 2011
Default help VB

can some one tell me whats wrong with this code

Code:
Select Code
Private Sub btnDisplay_Click( . . . )  Handles btnDisplay. Click
‘Toggle switch from on to off and from off to on.
Dim switchOn As Boolean
switchOn = CBool( InputBox( " Enter True or False. " ,  " The switch is on. " ) )
If switchOn Then
switchOn = False
End If
If Not switchOn Then
switchOn = True
End If
txtOutput. Text = CStr( switchOn)
End Sub
and also

Code:
Select Code
Private Sub btnDisplay_Click( . . . )  Handles btnDisplay. Click
‘Display twice the length of a word.
Dim word As String
word = InputBox( " Enter your favorite word " ) 
txtOutput.Text = “When the word is written twice, “ &
                             Twice (word) & “  letters are used.” 
End Sub
Function Twice (w As String) As Integer
‘Compute twice the length of a string.
Dim len As Integer
               Return len = 2 * w.Length
End Function
 
pencil42
Old
(Last edited by pencil42; 12th March 2014 at 09:08 AM.)
#2  
pencil42's Avatar
Member
Thanks Meter 2
Posts: 67
Join Date: Feb 2014
Location: Kraków

 
DONATE TO ME
[s]Is that java? I haven't programmed in a while, if that's java then you need ; at the end of line [/s]

Edit: oh that's vb, disregard my post

Sent from my Xperia L using Tapatalk
Device History
 
Nokia 6020 -> Nokia 6500 Slide -> Nokia E51 -> Samsung Galaxy Gio -> Sony Xperia L

Current Device:
Sony Xperia L

ROM: Stock 4.2.2 | Kernel: Stock | FW: (also stock) 15.3.A.0.26
No root

Samsung Galaxy Gio

ROM: LeWa OS 13.05.31 | Kernel: Provided with LeWa OS (I think?) | FW: No idea
Root ofc ^^
 
Archer
Old
#3  
Archer's Avatar
Senior Moderator / Recognized Developer - (Un)Recognized Pole Dancer
Thanks Meter 3952
Posts: 13,648
Join Date: Jul 2008
Location: Northampton
Quote:
Originally Posted by fujirio View Post
can some one tell me whats wrong with this code
The first one is wrong where you do this...

Code:
Select Code
If switchOn Then
switchOn = False
End If
If Not switchOn Then
switchOn = True
End If
You need an else or you're setting it to false and then saying "if it's false make it true" immediately after....

Code:
Select Code
If switchOn Then
switchOn = False
Else
switchOn = True
End If
Also, I'd recommend looking at using MessageBox as you can show a message and specify what buttons to have - MUCH better than asking someone to type true or false (and then have to worry about people typing other things, or spelling mistakes or upper/lower case characters).

The second one is wrong in the Twice function. You are returning the value of setting the variable len, not the actual value of it. It's easier to get rid of the variable in this case as it serves no purpose...

Code:
Select Code
Function Twice (w As String) As Integer
‘Compute twice the length of a string.
               Return 2 * w.Length
End Function
.
"I live by my own rules, nobody else's, not even my own."
.
My xda links

New User Guide | XDA Forum Rules | 10 Posts - Why and How? | Admins & Mods | My xda Bookmarks

.

.
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes