uname = txtUser.Text
pword = txtPass.Text
counter = 0
flag = 0
'Open file for reading into Current array, then close the file once all files are in the array
'Counter to track how many entries are in the file
FileOpen(1, CurDir() & "\Users.txt", OpenMode.Input)
While Not EOF(1)
Input(1, Current(counter).username)
Input(1, Current(counter).password)
counter = counter + 1
End While
FileClose(1)
'Compare the username and password input to the usernames and passwords in the users file
'And change a flag accordingly to true if there is a match, else false if there is not
For index = 0 To counter - 1
If flag = False Then
If Current(index).username = uname Then
If Current(index).password = pword Then
flag = 1
Else : flag = 0
End If
Else : flag = 0
End If
End If
Next
'If the flag is true, close the form and load the main program, otherwise display a message that
'the user name and/or password are incorrect
If flag = True Then
Me.Hide()
frmHome.Show()
Else
MsgBox("Invalid Username or Password")
End If
End Sub
Do you necessarily need the user name enrypted?
Have a look at System.Security.Cryptography (http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx)
It looks to me that he is prompting for it, via a textbox. The encryption is for storing them in a database (or flat file as the case appears to be right now).
This is a bit of an off topic question, but I am doing Visual Basic for my Software Development Unit.
What's the difference between between Visual Basic & VB.net?
No this isn't coursework I am just curious.
Private Sub cmbHosp_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbHosp.SelectedIndexChanged
template.hospital = cmbHosp.SelectedIndex
End Sub
FileOpen(1, CurDir() & "\Hospital.txt", OpenMode.Append)
Write(1, template.hospital)
FileClose(1)
namespace K_OS_SlimDX
{
public class CustomVertex
{
public class TransformedColored : CustomVertex
{
}
}
}
namespace K_OS_SlimDX
{
abstract class CustomVertex
{
}
public class TransformedColored : CustomVertex
{
}
}
i private void btnBereken_Click(object sender, EventArgs e)
{
int beurs = Convert.ToInt32(chkBeurs.Checked);
int kamers = Convert.ToInt32(chkKamers.Checked);
int actief = Convert.ToInt32(chkActief.Checked);
int som;
if (chkBeurs.Checked)
{
beurs = 5;
}
else if (chkKamers.Checked)
{
kamers = 5;
}
else if (chkActief.Checked)
{
actief = 10;
}
som = 30 - beurs - kamers - actief;
txtTotaal.Text = Convert.ToString(som);
}
i private void btnBereken_Click(object sender, EventArgs e)
{
int beurs = Convert.ToInt32(chkBeurs.Checked);
int kamers = Convert.ToInt32(chkKamers.Checked);
int actief = Convert.ToInt32(chkActief.Checked);
int som;
if (chkBeurs.Checked)
{
beurs = 5;
}
if (chkKamers.Checked)
{
kamers = 5;
}
if (chkActief.Checked)
{
actief = 10;
}
som = 30 - beurs - kamers - actief;
txtTotaal.Text = Convert.ToString(som);
}
The problem is your code can only hit one of the branches. Fortunately, it is an easy fix:
That said, the behaviour looks weird. You seem to be setting each variable to 1 or 0 depending on if it is checked then checking if it's checked and setting it to a new value.Code:i private void btnBereken_Click(object sender, EventArgs e) { int beurs = Convert.ToInt32(chkBeurs.Checked); int kamers = Convert.ToInt32(chkKamers.Checked); int actief = Convert.ToInt32(chkActief.Checked); int som; if (chkBeurs.Checked) { beurs = 5; } if (chkKamers.Checked) { kamers = 5; } if (chkActief.Checked) { actief = 10; } som = 30 - beurs - kamers - actief; txtTotaal.Text = Convert.ToString(som); }
well the thing it was supposed to be is if you check the first one, the total which is 30 has to have 5 taken off, and same with the second and third but the third takes 10 off.
then i needed to make it read multiple checks but for some reason it will only do this 30 - 5 then it will se the other 2 checks as 1 instead of 10 or 5. my teacher explained it and i was like yeah right... im a game and server programmer not a simple calculation programmer lol
but atleast i now know what i did wrong. instead of if-if-if i did if-if else-if else. which means it will look for alternatives and change the values of the other checks as it cant figure it out.
thanks. i think you'll see alot of simple stuff that ill post here, just because i overthink everything. if the forum had a thanks or rep button youd get one straight away haha! so thanks man i appreciate the help
i private void btnBereken_Click(object sender, EventArgs e)
{
int som = 30;
if (chkBeurs.Checked)
{
som -= 5;
}
if (chkKamers.Checked)
{
som -= 5;
}
if (chkActief.Checked)
{
som -= 10;
}
txtTotaal.Text = Convert.ToString(som);
}
No worries. Simple stuff is fine, gotta start somewhere right?
I didn't want to rewrite your code before, just show you why you were only getting 1 of the checks to take effect. But out of curiosity, why not write that checkbox logic this way?
Code:i private void btnBereken_Click(object sender, EventArgs e) { int som = 30; if (chkBeurs.Checked) { som -= 5; } if (chkKamers.Checked) { som -= 5; } if (chkActief.Checked) { som -= 10; } txtTotaal.Text = Convert.ToString(som); }