Reading radio buttons from module in VB.net - vb.net

i have created this module and i know that the student and teacher in the structure student and teacher are put as string (these are stored as my radio buttons), but when i save these to the file, this works by saving a true or false value for the id and password. however, i am unable to read the radio buttons from another class.
this is my module class
Imports System.IO
Module user_info_mod
Structure user
<VBFixedString(3)> Dim name As String
<VBFixedString(3)> Dim password As String
<VBFixedString(7)> Dim student As String
<VBFixedString(3)> Dim teacher As String
End Structure
Public newuser As user
Public userNumber As Integer = FreeFile()
Public userrecordNumber As Integer = 1
Public Sub setRecordNumber()
Dim n As Byte = 0
FileOpen(userNumber, "D:\users.dat", OpenMode.Random, OpenAccess.Read)
While Not EOF(userNumber)
n = n + 1 'increments the record number of the user
FileGet(userNumber, newuser, n)
End While
userrecordNumber = n
FileClose(userNumber)
End Sub
End Module
this is where i am trying to read the radio button in the main file ( newuser.student=True)
Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
Dim password As String
password = txtPassword.Text
Dim username As String
username = txtUsername.Text
FileOpen(userNumber, "D:\users.dat", OpenMode.Random, OpenAccess.Read)
FileGet(userNumber, newuser, userrecordNumber)
If password = newuser.password And username = newuser.name And newuser.student = True Then
MsgBox("ID Accepted")
Dim frmNew As New Student_selection
frmNew.ShowDialog()
FileClose(userNumber)
Else
FileClose(userNumber)
MsgBox("ID is not accepted")
End If
End Sub
if i am to change the string to boolean in the module, this is not enabling me to save a user's file when setting the record number within the module, so what is the correct way in order to solve this problem?

problem has been solved. The order of the radio buttons within the module had to be changed first, and then changed to a Boolean. Dim student As Boolean

Related

Can I re-use a form to declare multiple variables?

I am creating a score tournament system. I have created an entry screen where a user can enter multiple scores for a group. When the submit button is pressed, I need the scores to scores to be logged so that they can go into lists on my leader board page.
Below is my current code. Is it possible to refresh the form every time the user selects submit, but also have the results from the form before it was refreshed be logged?
If not, I'm worried I would need to create a new form for each group. Surely this isn't the case?
Public Class GT_Entry
Dim Activityscore1 As Integer
Dim Activityscore2 As Integer
Dim Activityscore3 As Integer
Dim Activityscore4 As Integer
Dim Activityscore5 As Integer
Dim Groupname As String
Private Sub Submit_Click(sender As System.Object, e As System.EventArgs) Handles Submit.Click
Activityscore1 = R1S.Text
Activityscore2 = R2S.Text
Activityscore3 = R3S.Text
Activityscore4 = R4S.Text
Activityscore5 = R5S.Text
Groupname = GN.Text
GN.Clear()
R1S.Clear()
R2S.Clear()
R3S.Clear()
R4S.Clear()
R5S.Clear()
End Sub
There are several ways to approach your problem. I made a class to store the data. Then created a list of that class. Each time the user clicks Submit the data is added to the list. You can iterate the list and access the properties.
Private ScoreList As New List(Of GroupActivityScore)
Private Sub Submit_Click(sender As System.Object, e As System.EventArgs) Handles Submit.Click
Dim GAS As New GroupActivityScore
GAS.Score1 = CInt(R1S.Text)
GAS.Score2 = CInt(R2S.Text)
GAS.Score3 = CInt(R3S.Text)
GAS.Score4 = CInt(R4S.Text)
GAS.Score5 = CInt(R5S.Text)
GAS.GroupName = GN.Text
ScoreList.Add(GAS)
GN.Clear()
R1S.Clear()
R2S.Clear()
R3S.Clear()
R4S.Clear()
R5S.Clear()
End Sub
Public Class GroupActivityScore
Public Property Score1 As Integer
Public Property Score2 As Integer
Public Property Score3 As Integer
Public Property Score4 As Integer
Public Property Score5 As Integer
Public Property GroupName As String
End Class

Login Form - Not working

Struggling with creating a login from a text file database. The information needs to be manually entered into the text file before it works... see my code below for the form. Its not letting me login.
Public Class UserLogin
Private PWD As String
Public User As User
Public Users As List(Of User) = New List(Of User)
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
If isValidData() Then
If isValidUser() Then
MessageBox.Show("Login Successful")
Form2.Show()
Me.Hide()
Else
MessageBox.Show("Incorrect Username or password")
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message & vbCrLf & vbCrLf & ex.GetType.ToString & vbCrLf & vbCrLf & ex.StackTrace, "User Does not Exist")
End Try
End Sub
Private Function isValidData() As Boolean
Return Validator.IsPresent(TextBox1, "Username") AndAlso
Validator.IsPresent(TextBox2, "Password")
End Function
Private Function isValidUser() As Boolean
Return UserDB.ValidateUser("Username", "Password")
End Function
Public Sub setPath(cwd As String)
PWD = cwd
End Sub
End Class
User class below :
Public Class User
Public Sub New()
End Sub
Public Sub New(Username As String, Password As String)
Me.Username = Username
Me.Password = Password
End Sub
Public Property Username As String
Public Property Password As String
Public Function GetDisplayText(sep As String) As String
Dim text As String = Username & sep & Password
Return text
End Function
End Class
UserDB class Below
Imports System.IO
Public Class UserDB
Private Const Databasename = "C:\Depreciate\Users.txt"
Public User As New User
Public Shared Users As List(Of User) = New List(Of User)
Public Shared Function GetUsers(Dir As String) As List(Of User)
Dim Users As New List(Of User)
Dim textIn As New StreamReader(
New FileStream(Databasename, FileMode.OpenOrCreate, FileAccess.Read))
Do While textIn.Peek <> -1
Dim row As String = textIn.ReadLine
Dim columns As String() = row.Split(CChar(","))
Dim User As New User
User.Username = columns(0)
User.Password = columns(1)
Users.Add(User)
Loop
textIn.Close()
Return Users
End Function
Public Shared Function ValidateUser(username As String, password As String) As Boolean
Dim Validated = False
For Each userEntry As User In Users
If username = userEntry.Username AndAlso password = userEntry.Password Then
Validated = True
Exit For
End If
Next
Return Validated
End Function
End Class
looks like you compare all user names and passwords to the strings "Username" and "Password" by calling:
Return UserDB.ValidateUser("Username", "Password")
in isValidUser.Probably you should better pass the actual username and the password which the user has typed instead?
There are a couple of problems in your code:
First I can't see anywhere the call to UserDB.GetUsers that should initialize the list of users from the file. But also assuming that you have made the call in some other place, there is another problem in that method.
This line inside the GetUsers method creates a new variable of type List(Of User) and name it with the same name of the Shared one effectively hiding the one declared at the global class level
Dim Users As New List(Of User)
Then your code continue and fills a variable named Users but this variable is not the shared one declared at the class global level. Of course, when you search your username and password in the shared variable you don't find anything.
Just remove that line and let the call To GetUsers fill the same variable used in the check
(Of course I also assume that when you call UserDB.ValidateUser you will pass an actual Username and a password and not the placeholders string that you are using in the code above)

End of statement expected. - VB Code to WebService Error

I'm getting this error when trying to debug my VB code in Visual Studio to interact with a specific WebService .
Im not very familiar with Visual Basic.
The error is on the line Dim ticket_handle As String = " CR 1001 " ws.closeTicket ( Sid , " closed ticket " ticket_handle )
The complete code:
Imports System.IO Imports System.Xml
Imports System.Xml.Serialization
Imports WebReference
Partial Class _Default
Inherits System.Web.UI.Page
Dim ws As New USD_WebService
Dim sid As String
Dim userhandle, username, password As String
Dim attrVal(5), attr(0), prop(0) As String
Dim requestHandle, requestNumber As String
Dim persistent_id As String
Dim catAttrib(5) As String
Sub Main()
Dim ws As New USD_WebService
ws.Url = "http://hummer:8080/axis/services/USD_R11_WebService?wsdl"
Dim username, password
Dim sid
username = "servicedesk"
password = "password"
sid = ws.login(username, password)
Dim userhandle
userhandle = ws.getHandleForUserid(sid, username)
Dim USD As New WebReference.USD_WebService
sid = USD.login(username, password)
Dim ticket_handle As String = “cr:1001” ws.closeTicket(Sid,“ticket fechado”, ticket_handle)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ws.Url = "http://hummer:8080/axis/services/USD_R11_WebService?wsdl"
End Sub
End Class
Can anyone help me plis?!?!
In VB.NET, only one statement may be executed per line. Other languages, like Java or C# use a ';' to denote the end of a statement, however in VB.NET it is the end of a line. The compiler is trying to tell you that you have two statements on a single line and it expects there to only be one.
Dim ticket_handle As String = “cr:1001” ws.closeTicket(Sid,“ticket fechado”, ticket_handle)
Should be
Dim ticket_handle As String = “cr:1001”
ws.closeTicket(Sid,“ticket fechado”, ticket_handle)

Random access file visual basic 2012

I am having trouble making my record number unique in visual basic 2012 the code i have so far is overwriting the file that was previously saved??
my module
Imports System.IO
Module AssModule
Structure employee
' Public Name As String
' Public ID As String
<VBFixedString(30)> Dim name As String ' vb fixed string
<VBFixedString(5)> Dim id As String ' vb fixed string
End Structure
Structure transaction
<VBFixedString(5)> Dim id As String ' vb fixed string
Dim time As Date
<VBFixedString(3)> Dim type As String ' vb fixed string
End Structure
' Public fileSize As Integer = Len(index)
' Public Staff(100) As employee ' staff as new name for eployeee structure
Public myEmployee As employee
Public r As Integer = 5
Public fileNumber As Integer = FreeFile()
Public mySizerecordnumber As Integer = Len(myEmployee)
Public recordNumber As Integer
Public index As Byte
Public Sub setRecordNumber()
Dim n As Byte = 0
FileOpen(fileNumber, "binData.dat", OpenMode.Random, OpenAccess.Read)
While Not EOF(fileNumber)
n = n + 1
FileGet(fileNumber, myEmployee, n)
End While
recordNumber = n
FileClose(fileNumber)
End Sub
End Module
add employee button
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
For n = 0 To 3
FileOpen(fileNumber, "binData.dat", OpenMode.Random, OpenAccess.Write, , mySizerecordnumber)
myEmployee.id = txtID.Text
myEmployee.name = txtName.Text
recordNumber = recordNumber + 1
FilePut(fileNumber, myEmployee, recordNumber)
FileClose(fileNumber)
Next
Me.Close()
End Sub
OK, let's break down your btnSave_Click function.
For 0 to 3, each time, you: open the file, read it, put the result in myEmployee, then put it back in the file and close.
What you want to do (I think) is to save the new employee at the end of your file
You should open your file, move to the end, and save your new record:
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
setRecordNumber()
FileOpen(fileNumber, "binData.dat", OpenMode.Random, OpenAccess.Write, , mySizerecordnumber)
myEmployee.id = txtID.Text
myEmployee.name = txtName.Text
FilePut(fileNumber, myEmployee, recordNumber)
FileClose(fileNumber)
Me.Close()
End Sub

update value of a variable outside a class in VB.NET

I have a class derived from a Form, it has textbox for username and password and an OK button. I want it to behave like an InputBox so I can use it like this:
Dim Username As String = ""
Dim Password As String = ""
Dim authorization As New Authorization(Username, Password)
authorization.ShowDialog()
'The user will click OK and I will expect the Username and Password to change based on the user input
MsgBox(Username & " " & Password)
The Authorization class:
Public Class Authorization
Dim RefUsername As String
Dim RefPassword As String
Public Sub New(ByRef Username As String, ByRef Password As String)
InitializeComponent()
RefUsername = Username 'I'm trying to pass reference instead of value
RefPassword = Password 'I'm trying to pass reference instead of value
End Sub
Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AuthorizeButton.Click
RefUsername = Username.Text 'I'm trying to change value of variable outside the class
RefPassword = Password.Text 'I'm trying to change value of variable outside the class
Me.Close()
End Sub
End Class
In short, I want to change the value of variables outside the class when the user clicks the OK, how am I going to accomplish that?
You can just add properties to the class to modify it from outside like any other class:
Public Class Authorization
Friend Property RefUsername As String
Friend Property RefPassword As String
'this constructor isn't really necessary with this new approach,
'but I'll leave it as-is.
Public Sub New(ByRef Username As String, ByRef Password As String)
InitializeComponent()
RefUsername = Username '
RefPassword = Password
End Sub
Private Sub OKButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles AuthorizeButton.Click
Me.DialogResult = DialogResult.OK
End Sub
End Class
From the outside you then get username and password:
Dim Username As String = ""
Dim Password As String = ""
Dim authorization As New Authorization(Username, Password)
'this constructor isn't really necessary with this new approach,
'but I'll leave it as-is.
If authorization.ShowDialog() = DialogResult.OK Then
MsgBox(authorization.RefUsername & " " & authorization.RefPassword)
End If
Public Class Authorization
Dim RefUsername As String
Dim RefPassword As String
Public Sub New(ByRef Username As String, ByRef Password As String)
InitializeComponent()
RefUsername = Username 'I'm trying to pass reference instead of value
RefPassword = Password 'I'm trying to pass reference instead of value
End Sub
Private Shared Function PromptUser() As ReturnClass
Dim currentReturnClass as ReturnClass
// Dialog Goes Here
currentReturnClass.UserName = Username.Text
currentReturnClass.Password = Password.Text
Me.Close()
End Sub
End Class
private class ReturnClass
Dim userName as String
Dim password as String
Dim userAcceptedDialog as Boolean
' Setters and Getters
End Class
Your calling code:
Dim Username As String = "Default User"
Dim Password As String = "Default Password"
Dim authorization As New Authorization(Username, Password)
Dim myReturnClass as ReturnClass
myReturnClass = authorization.PromptUser()
MsgBox(myReturnClass.Username & " " & myReturnClass.Password)