User Tag List
Results 1 to 17 of 24
Thread: VIsual Basic
-
01-19-2004, 02:16 AM #1
VIsual Basic
Hi there !
I hope you guy who like Badminton also can help me in Visual Basic.
I am a beginner in VB .NET and have a problem.
My problem is :
I want to create 4 buttons (or other control), but all the 4 must be in an array, so the names must be like these : cntl(0), cntl(1), cntl(2) and cntl(3).
In VB6, I have no problem, because when I copy and paste the button (in design form), I will be askes, create in array or not. But in VB .NET, no question like that.
When I change the name of the control in its property to cntl(0) or button(1) enz, I got an error message, something like 'invalid name'.
So..... how to make the 4 buttons in an array ?
Please help me guys !!!!!
FYI : I use VB .NET Professional version 2003.
-
01-19-2004, 03:49 PM #2
i personally hate desining object arrays on those forms.
Why not just generate the buttons at runtime?
-
01-19-2004, 05:56 PM #3
Because I am new in VB .NET so I don't know how.
BigRedLemon, will you let me know how to generate the buttons at runtime ?
Thx.
-
01-19-2004, 09:00 PM #4
havent used MS compliers in awhile... is it server side or client side?
-
01-20-2004, 06:36 AM #5
Actually can be in server and client side.Originally posted by bigredlemon
havent used MS compliers in awhile... is it server side or client side?
Can you explain in general ?
-
01-20-2004, 11:44 PM #6
Is the complier on your local computer or on a server's computer?
was is the file extension of your saved program?
-
01-22-2004, 02:36 AM #7
Wauhhh......
Let's make it simple Brl. I am new in VB .NET and still learning.
I create a new project in VB .NET.
I have a TextBox for enter a sentence that consist of max. 12 words and a button to get it starts.
The program should create (a) button(s) as many as the words in the sentence.
If the sentence consist of 5 words, so I got 5 buttons.
If the sentence consist of 10 words, so I got 10 buttons.
Just that Brl.
-
01-22-2004, 09:02 AM #8
different code is used depending on where the code is being compiled. The gist of it would be something like:
The above code will not work, but you can reformat it with the right calls to make it work.Code:dim btnMyButtons(2) as array For n = 0 to 2 dim btnMyButtons(n) as new System.Windows.Forms.Button() btnMyButtons(n).property1 = some value btnMyButtons(n).property2 = some value Next n
Btw, i thought all buttons had to be declared as btnSomeName as standard coding procedure... its what microsoft recommends to make the code readable
-
01-22-2004, 09:30 AM #9
watch your FOR loop as it will exceed the array size.
-
01-22-2004, 09:48 AM #10
Brl,
I think we must write like this :
dim btnMyButtons(2) as array
For n = 0 to 1 Not --> for n = 0 to 2 (Thanks BadRad)
dim btnMyButtons(n) as new System.Windows.Forms.Button()
btnMyButtons(n).property1 = some value
btnMyButtons(n).property2 = some value
Next n
But I have red an article that say : VB .NET doesn't support controls array.
Does MyButtons(n) work ?
Hier you can read the article.
-
01-22-2004, 11:58 AM #11
iirc array(2) makes an array or (0), (1), and (2).... I only have a java complier on this computer so i have no way of finding out for sure.... You can always declare a vector and not have to worry about array sizes.Originally posted by badrad
watch your FOR loop as it will exceed the array size.
-
01-22-2004, 12:00 PM #12
it doesn't even support control arrays?
Have you considered C++?
-
01-22-2004, 03:13 PM #13
Exactly, Microsoft is evil. C++ is definetely the way to go (with use of Linux or UNIX)Originally posted by bigredlemon
it doesn't even support control arrays?
Have you considered C++?
-
01-22-2004, 05:06 PM #14
I stick to VB .NETOriginally posted by bigredlemon
it doesn't even support control arrays?
Have you considered C++?
I don't like C++, if I have to choose between C++ and C#.
I will choose C#.
Anyway....... my problem is in VB .NET.
-
01-22-2004, 05:30 PM #15
vb6 does allow the upper boundary (ie array(2) - {0,1,2)), but depending on which version of vb.net it might not (certain beta releases which I played with did not allow it (array(2) - {0,1) 2 was not allowed and returned "IndexOutOfRangeException". I think the current version fixed it to be consistent with vb6.Originally posted by bigredlemon
iirc array(2) makes an array or (0), (1), and (2).... I only have a java complier on this computer so i have no way of finding out for sure.... You can always declare a vector and not have to worry about array sizes.
-
01-29-2004, 06:27 PM #16
Give you a short code for this. I suppose you have one TextBox(named txtSentence) and one Button(named Button1) in your main form.
Eric
___________________________________________--
Private btns() As Button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim counter As Integer = 0
Dim word() As String = txtSentence.Text.Split(" "c)
For i = 0 To word.Length - 1
If word(i).Trim <> "" Then
ReDim Preserve btns(counter)
btns(counter) = New Button()
btns(counter).Text = word(i)
btns(counter).Top = 200
btns(counter).Width = 50
btns(counter).Height = 20
btns(counter).Left = 50 + (counter * 70)
Me.Controls.Add(btns(counter))
AddHandler btns(counter).Click, AddressOf ResponseButtonClick
counter += 1
End If
Next
End Sub
Private Sub ResponseButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show(sender.text)
End Sub
-
01-30-2004, 02:26 AM #17
then you have the same problem as before... a control array, which is not supported by his complier
Similar Threads
-
Grip modification to provide visual and tactile guide
By asmd6230 in forum GripReplies: 0: 11-22-2011, 10:20 AM -
Basic grip or Adjusted basic grip for smashing
By Crimz in forum Techniques / TrainingReplies: 24: 02-06-2010, 08:58 AM -
Training your Eyes - VISUAL FOCUS
By wedgewenis in forum Techniques / TrainingReplies: 6: 11-08-2004, 02:08 PM -
gym lighting and visual adjusting
By SystemicAnomaly in forum General ForumReplies: 13: 09-14-2004, 02:07 AM -
After so long, visual treat...
By wilfredlgf in forum World Championships 2003Replies: 8: 08-04-2003, 03:27 AM




Reply With Quote

Bookmarks