Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CommandButton problem after converting to VB.net

Status
Not open for further replies.

InsideEdge

Instructor
Apr 5, 2005
35
US
Hi, I converted my Visual Basic 6 to Visual Basic.net and got some errors. The one that I can’t seem to fix is the one below:

Before the upgrade the code looked like this:

If Form1.cmdEnglish(0).Value = True Then

Code to be executed

After the upgrade the line was changed to:

If Form1.DefInstance.cmdEnglish(1).Value = True Then

I checked msdn and found a reference that said that the PerformClick method would do the same thing as the Value would in VB6. The trouble is I can’t seem to find a way to use it to let me know if my button was clicked like I did in VB6. Can anyone help me fix this line of code?

The objective is to test whether the CommandButton was clicked.

Please help.

 
If the button is on form1, who do you want to know if it was clicked?
 
When a user clicks the button, the code calls a sub routain that then shows the user a question and a group of answers to chose from. There are 12 buttons on the form and each button calls a different routain.
 
I will tell you an other way that i think is better.
This looks like to me that each button will have to pass an 'argument' to an other form, like a number. Personally i would change the tag property of these buttons... Button1's tag to 1,Button2's tag to 2 , etc (This by design time).

Then have one and only one handler for click event, like:
Code:
private sub WhichButtonClicked(sender .. , e ..) Handles button1.click, button2.click , ... , button12.click

  dim i as integer
  i=ctype(ctype(sender,button).tag,integer)

  dim tmpForm as new QuestionsForm(i)
  tmpForm.ShowDialog()
  tmp.Dispose()
end sub


In the QuestionsForm you should overide the new sub like:
Code:
Public Class QuestionsForm

  private questionID as integer

  public sub new(byval id as integer)
    InitializeComponent()
    me.questionID = id
  end sub

  private sub load(sender...,e ..) handles mybase.load
    ' your code here
  end sub

end class

In short: I got the clicked buttons STRING TAG and after casting it to integer i passed it in questionsForm through it new sub. That form should now use the questionID variable to load the question. Could be text file, XML ...


Take a look at this code; it is not as hard as you may think.
Post again if something troubles you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top