|
-
Jul 5th, 2000, 05:27 PM
#1
Thread Starter
Hyperactive Member
I'm pretty sure my code below doesn't need to be repeated. I'd appreciate if someone could show me how to tidy it up a bit - it works fine, but I know it could be neater.
Thanks for any help!
'Two command buttons and a textbox. The command buttons are 'for back and forward, through the text.
Dim MyText(0 To 5), CurText
Private Sub Command1_Click()
MyText(0) = "Yadayada"
MyText(1) = "Chicaboom"
MyText(2) = "Spaceman!"
MyText(3) = "Everybody"
MyText(4) = "Mr Bombastic"
MyText(5) = "Get Up, Get Up!!"
If CurText <> 0 Then
Form1.Text1.Text = MyText(CurText - 1)
CurText = CurText - 1
End If
End Sub
Private Sub Command2_Click()
MyText(0) = "Yadayada"
MyText(1) = "Chicaboom"
MyText(2) = "Spaceman!"
MyText(3) = "Everybody"
MyText(4) = "Mr Bombastic"
MyText(5) = "Get Up, Get Up!!"
If CurText <> 5 Then
Form1.Text1.Text = MyText(CurText + 1)
CurText = CurText + 1
End If
If CurText = 5 Then
Form1.Text1.Text = MyText(CurText)
End If
End Sub
-
Jul 5th, 2000, 05:47 PM
#2
Frenzied Member
Just move the
MyText(0) = "Yadayada"
MyText(1) = "Chicaboom"
MyText(2) = "Spaceman!"
MyText(3) = "Everybody"
MyText(4) = "Mr Bombastic"
MyText(5) = "Get Up, Get Up!!"
into the Form_Load Event
-
Jul 5th, 2000, 05:54 PM
#3
Tidying up!
1) You can replace all the Form1.Text1.Text with Text1.Text, VB automatically knows it's on Form1.
2) Move variable initalization into your Form_Load event.
3) Try using TAB in order to tell apart nested code snippets.
Example:
instead of:
If i=1 then
select case
case b
b=j
end select
end if
try:
if i=1 then
select case
case b
b=j
end select
end if
it's much more readable.
put one empty line between code parts that do different stuff, again, in order to tell apart.
That's it
-
Jul 6th, 2000, 03:55 AM
#4
Thread Starter
Hyperactive Member
I have 'Form1.text1.text' because the above code is actually in a module which is called when the user clicks the back and forward buttons:
'In form1:
Private Sub Command1_Click()
Call backwards
End Sub
Private Sub Command2_Click()
Call forwards
End Sub
So I have to have 'Form1', so module will know what to do. Likewise, Sam, I can't use form_load. Is there any Module_Load event or something?
Public Sub backwards()
MyText(0) = "Yadayada"
MyText(1) = "Chicaboom"
MyText(2) = "Spaceman!"
MyText(3) = "Everybody"
MyText(4) = "Mr Bombastic"
MyText(5) = "Get Up, Get Up!!"
If CurText <> 0 Then
Form1.Text1.Text = MyText(CurText - 1)
CurText = CurText - 1
End If
End Sub
Public Sub forwards()
MyText(0) = "Yadayada"
MyText(1) = "Chicaboom"
MyText(2) = "Spaceman!"
MyText(3) = "Everybody"
MyText(4) = "Mr Bombastic"
MyText(5) = "Get Up, Get Up!!"
If CurText <> 5 Then
Form1.Text1.Text = MyText(CurText + 1)
CurText = CurText + 1
End If
If CurText = 5 Then
Form1.Text1.Text = MyText(CurText)
End If
End Sub
-
Jul 6th, 2000, 04:09 AM
#5
Member
Try this :
Even if your code is in a module, you can put it in then Form_Load of the Form you first call (see the properties of your project).
You can remove the .text of your textbox because it is the textbox default property (it's a detail but more easy to read)
put some tabulations to your code as scOrp said :
If a=x Then
a=4
Else
a=9
Endif
will done:
If a=x Then
a=4
Else: a=9
Endif
for now, it's the only thing I can tell you.
-
Jul 6th, 2000, 04:11 AM
#6
Fanatic Member
So make a init sub in the mosule that initilaes the values. Call this from form1's load event.
Code:
Private Sub InitTextValues()
MyText(0) = "Yadayada"
MyText(1) = "Chicaboom"
MyText(2) = "Spaceman!"
MyText(3) = "Everybody"
MyText(4) = "Mr Bombastic"
MyText(5) = "Get Up, Get Up!!"
End Sub
'Form1
Private Sub Form_Load()
InitTextValues
End Sub
Iain, thats with an i by the way!
-
Jul 6th, 2000, 04:11 AM
#7
Member
Archhhhhhh
..., the spaces don't appear!!!!!!!!!!
Eh, Lain17, Can you tell me how you did to insert pretty form code in your reply ?
[Edited by (B2F)Tom on 07-06-2000 at 05:18 AM]
-
Jul 6th, 2000, 04:19 AM
#8
Fanatic Member
(B2F)Tom,
Check out :
http://forums.vb-world.net/index.php?action=bbcode
The name is Iain17 any way. Thats with an i. Everyone seems to get that wrong. Oh well.
Iain, thats with an i by the way!
-
Jul 6th, 2000, 04:23 AM
#9
Member
Sorry Iain17, I'll never do that again.
Anyway, thanks for your tip !
-
Jul 6th, 2000, 04:24 AM
#10
Fanatic Member
No worries mate.
Maybe i will have to include in my signature that it is an i.
Iain, thats with an i by the way!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|