Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27026

VS 2010 [RESOLVED] variable used before it has been assigned a value

$
0
0
Hi folks.

I have a button, textbox, and some radio buttons inside a groupbox. I enter text into the textbox, and select a radio button, and then click the button. The program stores the text that was entered, as well as the name of the radiobutton in a file. Why am I getting the "variable used before it has been assigned a value' for the freq variable? The value had already been assigned in the For Each loop?

Thanks in advance.

EDIT: I am also unsuccessfully trying to add a space between the text and the name of the radiobutton when the string is written to the file.

Code:

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim rButton As RadioButton
        Dim freq As String
        Dim NewEvent As String
        For Each rButton In GroupBox1.Controls.OfType(Of RadioButton)()
            If rButton.checked Then
                freq = rButton.Name
            End If
        Next
        NewEvent = txtNewEventAdd.Text & freq
        My.Computer.FileSystem.WriteAllText("events.txt", NewEvent, True)
        txtEventDisplay.Text = My.Computer.FileSystem.ReadAllText("events.txt")
    End Sub

End Class


Viewing all articles
Browse latest Browse all 27026

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>