8 Replies - 327 Views - Last Post: 08 October 2019 - 08:15 AM Rate Topic: -----

#1 zeroofmhx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 02-October 10

string datatype on List (Of String)

Posted 07 October 2019 - 02:19 AM

Hi i do have this code for checking user roles in checkbox which if checked will flag the string as "1" value. The defined strings where inserted to a List(Of String) for validation purposes and if string is equal to "" it will change to "0" i cant figure out to change the value of strings and will retain the string value for inserting sql query what happens it will not copy the values set to List (Of String). string values are up to 50 records

Dim a1,a2,a3 as String
Dim arr as List(Of String)

a1="1"
a2="1"
a3=""

For i = to aar.count -1
if aar(i) is Nothing Then

aar(i)="0"

End If

Next

//insert sql query




Is This A Good Question/Topic? 0
  • +

Replies To: string datatype on List (Of String)

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6829
  • View blog
  • Posts: 28,318
  • Joined: 12-December 12

Re: string datatype on List (Of String)

Posted 07 October 2019 - 06:09 AM

I don't really understand your question, but, there is no connection between variables a1,a2, a3 and the array aar. That is, assigning a value to a1 will not put it into aar(0).
Was This Post Helpful? 0
  • +
  • -

#3 zeroofmhx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 02-October 10

Re: string datatype on List (Of String)

Posted 07 October 2019 - 06:55 AM

View Postandrewsw, on 07 October 2019 - 06:09 AM, said:

I don't really understand your question, but, there is no connection between variables a1,a2, a3 and the array aar. That is, assigning a value to a1 will not put it into aar(0).


okay :( ill do it manual. if I insert a1 to arr then for loop say a1 is in arr(0) the loop will check if a1 ="" then will become a1="0" and retain its value for sql insert since my other variables are no value at all
Was This Post Helpful? 0
  • +
  • -

#4 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 3040
  • View blog
  • Posts: 11,686
  • Joined: 03-December 12

Re: string datatype on List (Of String)

Posted 07 October 2019 - 09:05 AM

If you are inserting these values into the database, the table design is not in a good state. I say this because it sounds like you have a column or roles that could look like this

1,1,1,1,1,1,0,0,0,1,0
Was This Post Helpful? 0
  • +
  • -

#5 zeroofmhx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 02-October 10

Re: string datatype on List (Of String)

Posted 07 October 2019 - 07:21 PM

View Postastonecipher, on 07 October 2019 - 09:05 AM, said:

If you are inserting these values into the database, the table design is not in a good state. I say this because it sounds like you have a column or roles that could look like this

1,1,1,1,1,1,0,0,0,1,0



yes do you have any suggestion since you said its not in a good state?

This post has been edited by zeroofmhx: 07 October 2019 - 07:22 PM

Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15433
  • View blog
  • Posts: 61,843
  • Joined: 12-June 08

Re: string datatype on List (Of String)

Posted 07 October 2019 - 07:38 PM

Why a string and not bool?
Was This Post Helpful? 0
  • +
  • -

#7 zeroofmhx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 02-October 10

Re: string datatype on List (Of String)

Posted 07 October 2019 - 07:48 PM

View Postmodi123_1, on 07 October 2019 - 07:38 PM, said:

Why a string and not bool?

can i manipulate them in list (Of Boolean) like

Dim a1,a2,a3 as Boolean
Dim aar as New List (Of Boolean)

aar.add(a1)
aar.add(a2)
aar.add(a3)

for i=0 to aar.count-1

if aar(i) is nothing then
aar(i)=false

end if

next



thats i want to do if applicable i dont want to put checking like if a1 is nothing then a1=false and like 50 roles is there another way that this code will be like less lines than checking 50 variables
Was This Post Helpful? 0
  • +
  • -

#8 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 3040
  • View blog
  • Posts: 11,686
  • Joined: 03-December 12

Re: string datatype on List (Of String)

Posted 08 October 2019 - 04:39 AM

View Postzeroofmhx, on 07 October 2019 - 09:21 PM, said:

View Postastonecipher, on 07 October 2019 - 09:05 AM, said:

If you are inserting these values into the database, the table design is not in a good state. I say this because it sounds like you have a column or roles that could look like this

1,1,1,1,1,1,0,0,0,1,0



yes do you have any suggestion since you said its not in a good state?


The database would be something like Users, Roles, UserRoles. In there you would say that User A has access to these roles through the UserRoles table.


User
ID
Name

Roles
ID
Name
Description

UserRoles
ID
UserId
RoleId



That way you don't have to keep up with the order or saying they don't have access to Role C, because if it isn't in the UerRole table, they don't have access.
Was This Post Helpful? 0
  • +
  • -

#9 zeroofmhx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 02-October 10

Re: string datatype on List (Of String)

Posted 08 October 2019 - 08:15 AM

View Postastonecipher, on 08 October 2019 - 04:39 AM, said:

View Postzeroofmhx, on 07 October 2019 - 09:21 PM, said:

View Postastonecipher, on 07 October 2019 - 09:05 AM, said:

If you are inserting these values into the database, the table design is not in a good state. I say this because it sounds like you have a column or roles that could look like this

1,1,1,1,1,1,0,0,0,1,0



yes do you have any suggestion since you said its not in a good state?


The database would be something like Users, Roles, UserRoles. In there you would say that User A has access to these roles through the UserRoles table.


User
ID
Name

Roles
ID
Name
Description

UserRoles
ID
UserId
RoleId



That way you don't have to keep up with the order or saying they don't have access to Role C, because if it isn't in the UerRole table, they don't have access.


thanks i will edit the tables then
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1