How to use the Content of a List or Array as Variables
up vote
-1
down vote
favorite
I've JUST started doodling with VB.Net
and I need some advice for a small task I've given myself.
What I want is that the contents of a list can be used as variables.
I've made a "logon" thing" like this:
Sub Main()
Dim username As String
Dim password As Integer
Dim nope As String = "!!!NO ACCESS!!!"
Dim ukjent As String = "!!!UNKNOWN USER!!!"
Console.Write("Enter your name: ")
username = Console.ReadLine()
Console.Write("Enter Password: ")
password = Console.ReadLine()
If username = "jarvis" And password = 1337 Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Welcome Jarvis")
Console.WriteLine("Please enter numerical value")
Dim X As Decimal = Console.ReadLine()
Dim y As Decimal = Console.ReadLine()
Dim z As Decimal = Console.ReadLine()
Dim i As Decimal
i = X + y + z
Console.WriteLine(i)
Console.WriteLine()
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
End If
Console.ReadLine()
If I want to use lists where I input more "usernames" and more "passwords" how should I do this?
Could I do it like this?
Dim username() As String ={"User1","User2"}
Dim password() As Integer ={ 123, 321}
How would I recall the values in the lists?
I know for now I'm not considering matching user1 to password 123. but that can come at a later stage, trying to build piece by piece.
.net vb.net
New contributor
|
show 2 more comments
up vote
-1
down vote
favorite
I've JUST started doodling with VB.Net
and I need some advice for a small task I've given myself.
What I want is that the contents of a list can be used as variables.
I've made a "logon" thing" like this:
Sub Main()
Dim username As String
Dim password As Integer
Dim nope As String = "!!!NO ACCESS!!!"
Dim ukjent As String = "!!!UNKNOWN USER!!!"
Console.Write("Enter your name: ")
username = Console.ReadLine()
Console.Write("Enter Password: ")
password = Console.ReadLine()
If username = "jarvis" And password = 1337 Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Welcome Jarvis")
Console.WriteLine("Please enter numerical value")
Dim X As Decimal = Console.ReadLine()
Dim y As Decimal = Console.ReadLine()
Dim z As Decimal = Console.ReadLine()
Dim i As Decimal
i = X + y + z
Console.WriteLine(i)
Console.WriteLine()
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
End If
Console.ReadLine()
If I want to use lists where I input more "usernames" and more "passwords" how should I do this?
Could I do it like this?
Dim username() As String ={"User1","User2"}
Dim password() As Integer ={ 123, 321}
How would I recall the values in the lists?
I know for now I'm not considering matching user1 to password 123. but that can come at a later stage, trying to build piece by piece.
.net vb.net
New contributor
Firstly, look into "concurrent arrays", which is what you're talking about there. After that, look into theDictionary
class in VB, which is a better option than two concurrent arrays when one array would be the natural identifiers. Also, you could consider creating a type (class or structure) that represents a single record (User
withUserName
andPassword
properties) and then create a single array or collection of objects of that type.
– jmcilhinney
2 days ago
Also note that arrays are fixed-length, so you should consider using collections rather than arrays if you want to add and/or remove items. In that case, aList(Of String)
and aList(Of Integer)
would be the way to go, although aDictionary(Of String, Integer)
is also a collection that can grow and shrink, as would be aList(Of User)
.
– jmcilhinney
2 days ago
ahh.. thank you. Managed to get it working ish whith the dictionary function. But in a dictionary when you use: Users.Add("User",Password) - could you give this a name. so that the key and value has to come from the same place in the dictionary ?
– Ehau83
2 days ago
They already do come from the same place. The whole point of aDictionary
is that the key is just that: a key. It is what you use to access the corresponding value. If you useUsers.Add("User", 123)
thenUsers("User")
will return 123. You can also lop through theDictionary
to getKeyValuePair
objects where, in that example, theKey
property would be "User" and theValue
property would be 123.
– jmcilhinney
2 days ago
yes. but if i have added: User1, 123 User2, 321 and type inn user1 - 321 i will get a true return.
– Ehau83
2 days ago
|
show 2 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I've JUST started doodling with VB.Net
and I need some advice for a small task I've given myself.
What I want is that the contents of a list can be used as variables.
I've made a "logon" thing" like this:
Sub Main()
Dim username As String
Dim password As Integer
Dim nope As String = "!!!NO ACCESS!!!"
Dim ukjent As String = "!!!UNKNOWN USER!!!"
Console.Write("Enter your name: ")
username = Console.ReadLine()
Console.Write("Enter Password: ")
password = Console.ReadLine()
If username = "jarvis" And password = 1337 Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Welcome Jarvis")
Console.WriteLine("Please enter numerical value")
Dim X As Decimal = Console.ReadLine()
Dim y As Decimal = Console.ReadLine()
Dim z As Decimal = Console.ReadLine()
Dim i As Decimal
i = X + y + z
Console.WriteLine(i)
Console.WriteLine()
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
End If
Console.ReadLine()
If I want to use lists where I input more "usernames" and more "passwords" how should I do this?
Could I do it like this?
Dim username() As String ={"User1","User2"}
Dim password() As Integer ={ 123, 321}
How would I recall the values in the lists?
I know for now I'm not considering matching user1 to password 123. but that can come at a later stage, trying to build piece by piece.
.net vb.net
New contributor
I've JUST started doodling with VB.Net
and I need some advice for a small task I've given myself.
What I want is that the contents of a list can be used as variables.
I've made a "logon" thing" like this:
Sub Main()
Dim username As String
Dim password As Integer
Dim nope As String = "!!!NO ACCESS!!!"
Dim ukjent As String = "!!!UNKNOWN USER!!!"
Console.Write("Enter your name: ")
username = Console.ReadLine()
Console.Write("Enter Password: ")
password = Console.ReadLine()
If username = "jarvis" And password = 1337 Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Welcome Jarvis")
Console.WriteLine("Please enter numerical value")
Dim X As Decimal = Console.ReadLine()
Dim y As Decimal = Console.ReadLine()
Dim z As Decimal = Console.ReadLine()
Dim i As Decimal
i = X + y + z
Console.WriteLine(i)
Console.WriteLine()
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
End If
Console.ReadLine()
If I want to use lists where I input more "usernames" and more "passwords" how should I do this?
Could I do it like this?
Dim username() As String ={"User1","User2"}
Dim password() As Integer ={ 123, 321}
How would I recall the values in the lists?
I know for now I'm not considering matching user1 to password 123. but that can come at a later stage, trying to build piece by piece.
.net vb.net
.net vb.net
New contributor
New contributor
edited 2 days ago
Lankymart
11.4k43896
11.4k43896
New contributor
asked 2 days ago
Ehau83
1
1
New contributor
New contributor
Firstly, look into "concurrent arrays", which is what you're talking about there. After that, look into theDictionary
class in VB, which is a better option than two concurrent arrays when one array would be the natural identifiers. Also, you could consider creating a type (class or structure) that represents a single record (User
withUserName
andPassword
properties) and then create a single array or collection of objects of that type.
– jmcilhinney
2 days ago
Also note that arrays are fixed-length, so you should consider using collections rather than arrays if you want to add and/or remove items. In that case, aList(Of String)
and aList(Of Integer)
would be the way to go, although aDictionary(Of String, Integer)
is also a collection that can grow and shrink, as would be aList(Of User)
.
– jmcilhinney
2 days ago
ahh.. thank you. Managed to get it working ish whith the dictionary function. But in a dictionary when you use: Users.Add("User",Password) - could you give this a name. so that the key and value has to come from the same place in the dictionary ?
– Ehau83
2 days ago
They already do come from the same place. The whole point of aDictionary
is that the key is just that: a key. It is what you use to access the corresponding value. If you useUsers.Add("User", 123)
thenUsers("User")
will return 123. You can also lop through theDictionary
to getKeyValuePair
objects where, in that example, theKey
property would be "User" and theValue
property would be 123.
– jmcilhinney
2 days ago
yes. but if i have added: User1, 123 User2, 321 and type inn user1 - 321 i will get a true return.
– Ehau83
2 days ago
|
show 2 more comments
Firstly, look into "concurrent arrays", which is what you're talking about there. After that, look into theDictionary
class in VB, which is a better option than two concurrent arrays when one array would be the natural identifiers. Also, you could consider creating a type (class or structure) that represents a single record (User
withUserName
andPassword
properties) and then create a single array or collection of objects of that type.
– jmcilhinney
2 days ago
Also note that arrays are fixed-length, so you should consider using collections rather than arrays if you want to add and/or remove items. In that case, aList(Of String)
and aList(Of Integer)
would be the way to go, although aDictionary(Of String, Integer)
is also a collection that can grow and shrink, as would be aList(Of User)
.
– jmcilhinney
2 days ago
ahh.. thank you. Managed to get it working ish whith the dictionary function. But in a dictionary when you use: Users.Add("User",Password) - could you give this a name. so that the key and value has to come from the same place in the dictionary ?
– Ehau83
2 days ago
They already do come from the same place. The whole point of aDictionary
is that the key is just that: a key. It is what you use to access the corresponding value. If you useUsers.Add("User", 123)
thenUsers("User")
will return 123. You can also lop through theDictionary
to getKeyValuePair
objects where, in that example, theKey
property would be "User" and theValue
property would be 123.
– jmcilhinney
2 days ago
yes. but if i have added: User1, 123 User2, 321 and type inn user1 - 321 i will get a true return.
– Ehau83
2 days ago
Firstly, look into "concurrent arrays", which is what you're talking about there. After that, look into the
Dictionary
class in VB, which is a better option than two concurrent arrays when one array would be the natural identifiers. Also, you could consider creating a type (class or structure) that represents a single record (User
with UserName
and Password
properties) and then create a single array or collection of objects of that type.– jmcilhinney
2 days ago
Firstly, look into "concurrent arrays", which is what you're talking about there. After that, look into the
Dictionary
class in VB, which is a better option than two concurrent arrays when one array would be the natural identifiers. Also, you could consider creating a type (class or structure) that represents a single record (User
with UserName
and Password
properties) and then create a single array or collection of objects of that type.– jmcilhinney
2 days ago
Also note that arrays are fixed-length, so you should consider using collections rather than arrays if you want to add and/or remove items. In that case, a
List(Of String)
and a List(Of Integer)
would be the way to go, although a Dictionary(Of String, Integer)
is also a collection that can grow and shrink, as would be a List(Of User)
.– jmcilhinney
2 days ago
Also note that arrays are fixed-length, so you should consider using collections rather than arrays if you want to add and/or remove items. In that case, a
List(Of String)
and a List(Of Integer)
would be the way to go, although a Dictionary(Of String, Integer)
is also a collection that can grow and shrink, as would be a List(Of User)
.– jmcilhinney
2 days ago
ahh.. thank you. Managed to get it working ish whith the dictionary function. But in a dictionary when you use: Users.Add("User",Password) - could you give this a name. so that the key and value has to come from the same place in the dictionary ?
– Ehau83
2 days ago
ahh.. thank you. Managed to get it working ish whith the dictionary function. But in a dictionary when you use: Users.Add("User",Password) - could you give this a name. so that the key and value has to come from the same place in the dictionary ?
– Ehau83
2 days ago
They already do come from the same place. The whole point of a
Dictionary
is that the key is just that: a key. It is what you use to access the corresponding value. If you use Users.Add("User", 123)
then Users("User")
will return 123. You can also lop through the Dictionary
to get KeyValuePair
objects where, in that example, the Key
property would be "User" and the Value
property would be 123.– jmcilhinney
2 days ago
They already do come from the same place. The whole point of a
Dictionary
is that the key is just that: a key. It is what you use to access the corresponding value. If you use Users.Add("User", 123)
then Users("User")
will return 123. You can also lop through the Dictionary
to get KeyValuePair
objects where, in that example, the Key
property would be "User" and the Value
property would be 123.– jmcilhinney
2 days ago
yes. but if i have added: User1, 123 User2, 321 and type inn user1 - 321 i will get a true return.
– Ehau83
2 days ago
yes. but if i have added: User1, 123 User2, 321 and type inn user1 - 321 i will get a true return.
– Ehau83
2 days ago
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
You don't want your user to know if it is the username or password or both that is wrong; only that the long-in is not valid. Don't help the hacker.
TryParse takes the string that user types in. Yes, it is a string even if numbers are typed in. Look up Console.ReadLine and you will see it returns a string.
TryParse will test the string to see if it can be converted to an integer. If it succeeds it will place the value into the password variable (in this example) and if it fails a zero will be placed in password.
The .Keys method of the Dictionary returns a collection of all the keys. We check with the Contains method to see if the input username is present. If it is we use the key username to retrieve the value associated with it. If the username is not there we kick the bum out.
Finally we checked the stored password against the entered password.
All this checking is because we can't trust user to enter exactly what we expect them to enter.
Sub Main()
Dim X, Y, Z As Decimal
Dim StoredPassword As Integer 'refers to what is in the Dictionary
Dim username As String = ""
Dim password As Integer
Dim nope As String = "!!!NO ACCESS!!!"
Dim Users As New Dictionary(Of String, Integer) From {{"Mathew", 123}, {"Mark", 456}, {"Luke", 321}}
Console.Write("Enter your name: ")
username = Console.ReadLine()
Console.Write("Enter Password: ")
Integer.TryParse(Console.ReadLine(), password)
If Users.Keys.Contains(username) Then
StoredPassword = Users(username)
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
Console.ReadLine()
End
End If
If StoredPassword = password Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Successful Login")
Console.WriteLine($"Welcome {username}!")
Console.ForegroundColor = ConsoleColor.White
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
Console.ReadLine()
End
End If
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), X)
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), Y)
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), Z)
Dim i As Decimal
i = X + Y + Z
Console.WriteLine($"The sum is {i}")
Console.ReadLine() 'keeps the console window open
End Sub
Thanks Mary. but your code got the same problem as i do. you get "access" regardless of wich password in the dictionary you use. so if you use user "mark" and password "123" it will stillgrant acces. instead of denying.
– Ehau83
yesterday
The Contains method is case sensitive. mark will not match Mark. This code is tested and works correctly for me. Mark or mark and password 123 will get No Access. Start a new project and copy and paste my code to see if it works for you.
– Mary
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You don't want your user to know if it is the username or password or both that is wrong; only that the long-in is not valid. Don't help the hacker.
TryParse takes the string that user types in. Yes, it is a string even if numbers are typed in. Look up Console.ReadLine and you will see it returns a string.
TryParse will test the string to see if it can be converted to an integer. If it succeeds it will place the value into the password variable (in this example) and if it fails a zero will be placed in password.
The .Keys method of the Dictionary returns a collection of all the keys. We check with the Contains method to see if the input username is present. If it is we use the key username to retrieve the value associated with it. If the username is not there we kick the bum out.
Finally we checked the stored password against the entered password.
All this checking is because we can't trust user to enter exactly what we expect them to enter.
Sub Main()
Dim X, Y, Z As Decimal
Dim StoredPassword As Integer 'refers to what is in the Dictionary
Dim username As String = ""
Dim password As Integer
Dim nope As String = "!!!NO ACCESS!!!"
Dim Users As New Dictionary(Of String, Integer) From {{"Mathew", 123}, {"Mark", 456}, {"Luke", 321}}
Console.Write("Enter your name: ")
username = Console.ReadLine()
Console.Write("Enter Password: ")
Integer.TryParse(Console.ReadLine(), password)
If Users.Keys.Contains(username) Then
StoredPassword = Users(username)
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
Console.ReadLine()
End
End If
If StoredPassword = password Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Successful Login")
Console.WriteLine($"Welcome {username}!")
Console.ForegroundColor = ConsoleColor.White
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
Console.ReadLine()
End
End If
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), X)
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), Y)
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), Z)
Dim i As Decimal
i = X + Y + Z
Console.WriteLine($"The sum is {i}")
Console.ReadLine() 'keeps the console window open
End Sub
Thanks Mary. but your code got the same problem as i do. you get "access" regardless of wich password in the dictionary you use. so if you use user "mark" and password "123" it will stillgrant acces. instead of denying.
– Ehau83
yesterday
The Contains method is case sensitive. mark will not match Mark. This code is tested and works correctly for me. Mark or mark and password 123 will get No Access. Start a new project and copy and paste my code to see if it works for you.
– Mary
yesterday
add a comment |
up vote
0
down vote
You don't want your user to know if it is the username or password or both that is wrong; only that the long-in is not valid. Don't help the hacker.
TryParse takes the string that user types in. Yes, it is a string even if numbers are typed in. Look up Console.ReadLine and you will see it returns a string.
TryParse will test the string to see if it can be converted to an integer. If it succeeds it will place the value into the password variable (in this example) and if it fails a zero will be placed in password.
The .Keys method of the Dictionary returns a collection of all the keys. We check with the Contains method to see if the input username is present. If it is we use the key username to retrieve the value associated with it. If the username is not there we kick the bum out.
Finally we checked the stored password against the entered password.
All this checking is because we can't trust user to enter exactly what we expect them to enter.
Sub Main()
Dim X, Y, Z As Decimal
Dim StoredPassword As Integer 'refers to what is in the Dictionary
Dim username As String = ""
Dim password As Integer
Dim nope As String = "!!!NO ACCESS!!!"
Dim Users As New Dictionary(Of String, Integer) From {{"Mathew", 123}, {"Mark", 456}, {"Luke", 321}}
Console.Write("Enter your name: ")
username = Console.ReadLine()
Console.Write("Enter Password: ")
Integer.TryParse(Console.ReadLine(), password)
If Users.Keys.Contains(username) Then
StoredPassword = Users(username)
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
Console.ReadLine()
End
End If
If StoredPassword = password Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Successful Login")
Console.WriteLine($"Welcome {username}!")
Console.ForegroundColor = ConsoleColor.White
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
Console.ReadLine()
End
End If
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), X)
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), Y)
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), Z)
Dim i As Decimal
i = X + Y + Z
Console.WriteLine($"The sum is {i}")
Console.ReadLine() 'keeps the console window open
End Sub
Thanks Mary. but your code got the same problem as i do. you get "access" regardless of wich password in the dictionary you use. so if you use user "mark" and password "123" it will stillgrant acces. instead of denying.
– Ehau83
yesterday
The Contains method is case sensitive. mark will not match Mark. This code is tested and works correctly for me. Mark or mark and password 123 will get No Access. Start a new project and copy and paste my code to see if it works for you.
– Mary
yesterday
add a comment |
up vote
0
down vote
up vote
0
down vote
You don't want your user to know if it is the username or password or both that is wrong; only that the long-in is not valid. Don't help the hacker.
TryParse takes the string that user types in. Yes, it is a string even if numbers are typed in. Look up Console.ReadLine and you will see it returns a string.
TryParse will test the string to see if it can be converted to an integer. If it succeeds it will place the value into the password variable (in this example) and if it fails a zero will be placed in password.
The .Keys method of the Dictionary returns a collection of all the keys. We check with the Contains method to see if the input username is present. If it is we use the key username to retrieve the value associated with it. If the username is not there we kick the bum out.
Finally we checked the stored password against the entered password.
All this checking is because we can't trust user to enter exactly what we expect them to enter.
Sub Main()
Dim X, Y, Z As Decimal
Dim StoredPassword As Integer 'refers to what is in the Dictionary
Dim username As String = ""
Dim password As Integer
Dim nope As String = "!!!NO ACCESS!!!"
Dim Users As New Dictionary(Of String, Integer) From {{"Mathew", 123}, {"Mark", 456}, {"Luke", 321}}
Console.Write("Enter your name: ")
username = Console.ReadLine()
Console.Write("Enter Password: ")
Integer.TryParse(Console.ReadLine(), password)
If Users.Keys.Contains(username) Then
StoredPassword = Users(username)
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
Console.ReadLine()
End
End If
If StoredPassword = password Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Successful Login")
Console.WriteLine($"Welcome {username}!")
Console.ForegroundColor = ConsoleColor.White
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
Console.ReadLine()
End
End If
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), X)
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), Y)
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), Z)
Dim i As Decimal
i = X + Y + Z
Console.WriteLine($"The sum is {i}")
Console.ReadLine() 'keeps the console window open
End Sub
You don't want your user to know if it is the username or password or both that is wrong; only that the long-in is not valid. Don't help the hacker.
TryParse takes the string that user types in. Yes, it is a string even if numbers are typed in. Look up Console.ReadLine and you will see it returns a string.
TryParse will test the string to see if it can be converted to an integer. If it succeeds it will place the value into the password variable (in this example) and if it fails a zero will be placed in password.
The .Keys method of the Dictionary returns a collection of all the keys. We check with the Contains method to see if the input username is present. If it is we use the key username to retrieve the value associated with it. If the username is not there we kick the bum out.
Finally we checked the stored password against the entered password.
All this checking is because we can't trust user to enter exactly what we expect them to enter.
Sub Main()
Dim X, Y, Z As Decimal
Dim StoredPassword As Integer 'refers to what is in the Dictionary
Dim username As String = ""
Dim password As Integer
Dim nope As String = "!!!NO ACCESS!!!"
Dim Users As New Dictionary(Of String, Integer) From {{"Mathew", 123}, {"Mark", 456}, {"Luke", 321}}
Console.Write("Enter your name: ")
username = Console.ReadLine()
Console.Write("Enter Password: ")
Integer.TryParse(Console.ReadLine(), password)
If Users.Keys.Contains(username) Then
StoredPassword = Users(username)
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
Console.ReadLine()
End
End If
If StoredPassword = password Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Successful Login")
Console.WriteLine($"Welcome {username}!")
Console.ForegroundColor = ConsoleColor.White
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(nope)
Console.ReadLine()
End
End If
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), X)
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), Y)
Console.WriteLine("Please enter numerical value")
Decimal.TryParse(Console.ReadLine(), Z)
Dim i As Decimal
i = X + Y + Z
Console.WriteLine($"The sum is {i}")
Console.ReadLine() 'keeps the console window open
End Sub
answered yesterday
Mary
2,4902617
2,4902617
Thanks Mary. but your code got the same problem as i do. you get "access" regardless of wich password in the dictionary you use. so if you use user "mark" and password "123" it will stillgrant acces. instead of denying.
– Ehau83
yesterday
The Contains method is case sensitive. mark will not match Mark. This code is tested and works correctly for me. Mark or mark and password 123 will get No Access. Start a new project and copy and paste my code to see if it works for you.
– Mary
yesterday
add a comment |
Thanks Mary. but your code got the same problem as i do. you get "access" regardless of wich password in the dictionary you use. so if you use user "mark" and password "123" it will stillgrant acces. instead of denying.
– Ehau83
yesterday
The Contains method is case sensitive. mark will not match Mark. This code is tested and works correctly for me. Mark or mark and password 123 will get No Access. Start a new project and copy and paste my code to see if it works for you.
– Mary
yesterday
Thanks Mary. but your code got the same problem as i do. you get "access" regardless of wich password in the dictionary you use. so if you use user "mark" and password "123" it will stillgrant acces. instead of denying.
– Ehau83
yesterday
Thanks Mary. but your code got the same problem as i do. you get "access" regardless of wich password in the dictionary you use. so if you use user "mark" and password "123" it will stillgrant acces. instead of denying.
– Ehau83
yesterday
The Contains method is case sensitive. mark will not match Mark. This code is tested and works correctly for me. Mark or mark and password 123 will get No Access. Start a new project and copy and paste my code to see if it works for you.
– Mary
yesterday
The Contains method is case sensitive. mark will not match Mark. This code is tested and works correctly for me. Mark or mark and password 123 will get No Access. Start a new project and copy and paste my code to see if it works for you.
– Mary
yesterday
add a comment |
Ehau83 is a new contributor. Be nice, and check out our Code of Conduct.
Ehau83 is a new contributor. Be nice, and check out our Code of Conduct.
Ehau83 is a new contributor. Be nice, and check out our Code of Conduct.
Ehau83 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203502%2fhow-to-use-the-content-of-a-list-or-array-as-variables%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Firstly, look into "concurrent arrays", which is what you're talking about there. After that, look into the
Dictionary
class in VB, which is a better option than two concurrent arrays when one array would be the natural identifiers. Also, you could consider creating a type (class or structure) that represents a single record (User
withUserName
andPassword
properties) and then create a single array or collection of objects of that type.– jmcilhinney
2 days ago
Also note that arrays are fixed-length, so you should consider using collections rather than arrays if you want to add and/or remove items. In that case, a
List(Of String)
and aList(Of Integer)
would be the way to go, although aDictionary(Of String, Integer)
is also a collection that can grow and shrink, as would be aList(Of User)
.– jmcilhinney
2 days ago
ahh.. thank you. Managed to get it working ish whith the dictionary function. But in a dictionary when you use: Users.Add("User",Password) - could you give this a name. so that the key and value has to come from the same place in the dictionary ?
– Ehau83
2 days ago
They already do come from the same place. The whole point of a
Dictionary
is that the key is just that: a key. It is what you use to access the corresponding value. If you useUsers.Add("User", 123)
thenUsers("User")
will return 123. You can also lop through theDictionary
to getKeyValuePair
objects where, in that example, theKey
property would be "User" and theValue
property would be 123.– jmcilhinney
2 days ago
yes. but if i have added: User1, 123 User2, 321 and type inn user1 - 321 i will get a true return.
– Ehau83
2 days ago