Author |
Topic |
|
Lon2
Junior Member
USA
151 Posts |
Posted - 19 December 2008 : 10:58:14
|
Quick question: I'm adding some things to user profile so it displays. When the code line saysif strItem = "1" then Where is the option for 1 or 0? Or, is it automatically a 1 if there's content in that profile field?< |
|
Shaggy
Support Moderator
Ireland
6780 Posts |
Posted - 19 December 2008 : 11:41:59
|
It's checking the value of an application variable, which are populated by whatever you have selected or entered through your admin options.
< |
Search is your friend “I was having a mildly paranoid day, mostly due to the fact that the mad priest lady from over the river had taken to nailing weasels to my front door again.” |
|
|
Etymon
Advanced Member
United States
2385 Posts |
Posted - 19 December 2008 : 11:42:39
|
You imitate the way a value was coded in the configuration of the members section (Member Details Configuration) in the admin section and then create your own control from it. What you do is get into admin_config_members.asp and copy verbatim a table row that you want to imitate like Country:.
Copy and paste that table row for the strCountry area and then rename the variables to something else like, instead of strCountry, go with strItem, and rename the new Country: text to Item:.
Next, go into the config.asp file and do the same thing. Find the references for strCountry, copy and paste to the next line below, and then rename the new strCountry text to strItem.
Go back into your Member Details Configuration section, choose the value you want for Item: either On or Off. Then hit Submit. The variable will be automatically created into the FORUM_CONFIG_NEW table. And, that is where the value for your strMyItem will come from in you profile page.
That's one way of doing it.
You can set a variable in the profile without using the admin section, but it will be hard-coded instead of something you can change on the fly.
For just normal coding without database variable values ... think of coding as a conversation you are having with the server.
If you say to the server:
Lon2
Response.Write Lon2
The server, like anyone is not going to find it as having a value because it has not been associated with a value.
If you say:
if Lon2 = "1" then
That's the same as saying:
if = "1" then
Again, there is no association.
If you said:
Lon2 = ""
Then you have established an association.
Now if you say:
Lon2 = ""
Response.Write Lon2
That won't throw an error, but it will also write nothing to the browser because Lon2 equals nothing.
If you say to the server:
Lon2 = "1"
Response.Write Lon2
Then, the output to the browser will be the value or the number one.
Back to your question ... where it the option for 1 or 0?
The answer to where the option is, is that the option for 1 or 0 is the value that you give to strItem before you make a comparison against it ... like this:
Dim strItem
strItem = "0"
if strItem = "0" then Response.Write "0" elseif strItem = "1" then Response.Write "1" elseif strItem = "" then Response.Write "Nothing" else Response.Write "strItem does not equal 0 or 1 or Nothing." end if Response.End
That's how it is if you are starting from scratch as in you are not pulling a value from the database and associating it with an existing variable.< |
Edited by - Etymon on 19 December 2008 12:01:15 |
|
|
AnonJr
Moderator
United States
5768 Posts |
Posted - 19 December 2008 : 12:16:29
|
quote: if strItem = "0" then Response.Write "0" elseif strItem = "1" then Response.Write "1" elseif strItem = "" then Response.Write "Nothing" else Response.Write "strItem does not equal 0 or 1 or Nothing." end if Response.End
I know there are a lot of examples like this in the code, but for your sanity and the sanity of anyone trying to maintain your code, if you need more than one ElseIf, go to a Select Case...
Its a bit of a personal pet peeve, but it makes it easier to figure out at a glance what in God's green earth is going on and it makes it so easy to handle the "Case Else" bits.
Just an observation, take it for what its worth.< |
|
|
Etymon
Advanced Member
United States
2385 Posts |
Posted - 19 December 2008 : 13:32:28
|
LOL! Well, doing is living Anon.
Post your example too using Case, and this guy will have a great view from both sides of the fence. < |
|
|
AnonJr
Moderator
United States
5768 Posts |
Posted - 19 December 2008 : 13:44:34
|
Here's an example of what I mean. Instead of this:
quote:
if strItem = "0" then
Response.Write "0"
elseif strItem = "1" then
Response.Write "1"
elseif strItem = "" then
Response.Write "Nothing"
else
Response.Write "strItem does not equal 0 or 1 or Nothing."
end if
Response.End
Use this:
quote:
Select Case strItem
Case "0"
Response.Write("0")
Case "1"
Response.Write("1")
Case ""
Response.Write("Nothing")
Case Else
Response.Write("do whatever exception handling here.")
End Select
Makes it easier to add extra conditions, handle exceptions, and IMHO is easier to read, maintain, and recall 6 months later when you need to go back and figure out what you were thinking.< |
|
|
HuwR
Forum Admin
United Kingdom
20584 Posts |
Posted - 19 December 2008 : 13:51:48
|
it will also execute faster if it is a case statement rather than a serious of if else's as it does not have to evalute each step to find an match< |
|
|
Etymon
Advanced Member
United States
2385 Posts |
Posted - 19 December 2008 : 14:16:10
|
It's great to have the comparisons of examples so folks can understand the Select Case better. Thanks guys! < |
|
|
|
Topic |
|