Visual Basic .Net 2003 and Comments

  • Thread starter Thread starter Matrixhasu77
  • 11 comments
  • 741 views
Messages
2,491
Ok, here is my problem, I have written a program using Visual Basic .Net Studio 2003 and I am unable to figure out how to write comments into my source code without getting build errors. The command I have been using to designate comments has been two forward slashes(//) followed by the text I wish to use as a comment. Now this is what I have read from Microsoft's online help but it does not seem to work. Any ideas? They would be greatly appreciated.

My instructor hasn't bothered to discuss how to do this in a lecture yet so I am at a loss on how to do it.
 
So without the comments the program works?

In Java, /* and */ can also be used to start and close comments.
 
Code:
[size=3][color=navy]Private Sub[/color] About_Click()[/size]
[size=3]frmAbout.Visible = [color=navy]True[/color] [color=seagreen]' Displays About window[/color][/size]
[size=3] [/size]
[size=3][color=navy]End Sub[/color][/size]

You just add a ' before your comments and it will turn green. I believe the // is for C++, not Visual Basic.
 
Viper Zero
You just add a ' before your comments and it will turn green. I believe the // is for C++, not Visual Basic.
that is true 👍. The ' is what you'll be using for all your comments under VB

btw, if you have any vb questions, i've been working on and off with the damn language for 4 years now.
 
Thanks guys. So I take it that for just source code comments you use a ' like html has it's <!--Comment--> property for that language.

What I don't seem to understand is why Microsoft fails to mention this in its' online help or the fact that there seems to be no reference to it in my textbook for the course.

I had no clue on how to do such a simple thing like this. You'd think there would be a reference to it somewhere...
 
Matrixhasu77
I had no clue on how to do such a simple thing like this. You'd think there would be a reference to it somewhere...
they probably left that reference out because it's in every piece of sample code in the help file and in every VB textbook you buy
 
Matrixhasu77
Thanks guys. So I take it that for just source code comments you use a ' like html has it's <!--Comment--> property for that language.

What I don't seem to understand is why Microsoft fails to mention this in its' online help or the fact that there seems to be no reference to it in my textbook for the course.

I had no clue on how to do such a simple thing like this. You'd think there would be a reference to it somewhere...
I have the MSDN Library (Jan '04) which has helped me immensly. It's basically a huge reference to all the functions, properties and such for every language supported by Visual Studio .NET.

 
Ok, I am experiencing a little trouble with a one-dimensional array for a lab that I am in the process of attempting to do. I am trying to store values that are entered by the user into a fixed size array with a size of 100 units. I have set up a loop structure to automatically assign the input to an array variable. However, upon outputting the inputed variable at the end of the subrountine, I get the default value of zero.

Here is the code that is contained in my click event(at this point nothing is final):

Code:
btnAnalyze.Enabled = True
        Static LoopCtr As Integer
        Static Volts As Double
        If ValidateForm() = False Then
            Exit Sub
        End If
        txtCollectorVolts.Text = Volts
        For LoopCtr = 0 To 99
            CollectorVoltsArray(LoopCtr) = Volts
            txtCollectorVolts.Focus()
        Next LoopCtr
        fSampNumCounter += 1
        txtSampNum.Text = fSampNumCounter
        txtOutput.Text = txtOutput.Text & CollectorVoltsArray(99) & vbCrLf

I'm not too confident in my ability to use arrays at this point in time since I'm unsure how to go about storing data in them. Any ideas about this would be greatly appreciated as I can't figure out where I'm going wrong.

EDIT: I think i've fixed it as I was able to get the inputs to finally output to my text box. Nevermind for now.
 
Minor Problem... How do I make it so that pressing the enter key on the keyboard is the same as a click event/pressing a button? I've looked on MSDN and can't find any info that explains this.
 
Matrixhasu77
Minor Problem... How do I make it so that pressing the enter key on the keyboard is the same as a click event/pressing a button? I've looked on MSDN and can't find any info that explains this.
You'd have to add a KeyPress event to the button, then use an If statement to see if the pressed key is "Enter".

Code:
Private Sub Button1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress
    If e.KeyChar = "Enter" Then
        'Whatever is you want to do...
    End If
End Sub
 
Shannon
You'd have to add a KeyPress event to the button, then use an If statement to see if the pressed key is "Enter".

Code:
Private Sub Button1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress
    If e.KeyChar = "Enter" Then
        'Whatever is you want to do...
    End If
End Sub

Thanks, I figured it out awhile ago actually. All I had to do was set the Accept Button property of the click event to "Enter" and it worked.
 
Back