[RESOLVED] VB Script will not remove modified data from Database - Page 3
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 8 FirstFirst 123456 ... LastLast
Results 31 to 45 of 114

Thread: [RESOLVED] VB Script will not remove modified data from Database

  1. #31
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,845

    Re: VB Script will not remove modified data from Database

    Response.Write "<option STYLE='color: " & LinkColorRS("ColorCode") & " !important' value='" & LinkColorRS("ColorCode") & "'"
    If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Response.Write "selected"
    Response.Write">" & LinkColorRS("ColorName") & "</option>"
    That is also in a loop so you only want to grab the one that has been selected.
    Always use [code][/code] tags when posting code.

  2. #32
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by DataMiser View Post
    That is also in a loop so you only want to grab the one that has been selected.
    Hi and thanks again for your efforts and reply. I had to take some time out to go and help my son with a water leak in his house after he tried to fit a new kitchen sink !! If tried all sorts to actually extract the value of ColorName that I select with the new category and all without success. I either get variable undefined which I do understand, type mismatch, syntax error or unexpected end of statement plus a few others that perplex me just as much. Am I trying to do something that is not practical? Is it not possible to capture both the new category name and the colour I have chosen out of those defined in the database at the same point in time? Why does the hex value of that colour not translate to the colour name? I can extract that information ok. I add a category called TEST and select the colour Black and the information message will tell me that ......'The new category of 'TEST' with an associated colour of '#000' has been added to the database." So yeh ... still a bit confused. I understand how an sql query might look at a database and select details from specific fields, but where is the best place to put it? Would it be in the same code area that the open, connect and close DB statements are made? ....any advice?? much appreciated :-)

  3. #33
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,845

    Re: VB Script will not remove modified data from Database

    The place to put it depends on where and how you want to display it.

    Like I said you already have it there in that one piece of script you showed. You can assign it to a variable that you will use later in the script, just have to make sure you have the right scope on the variable or you can use a query and get it where you need it either will work with the variable being the faster since it does not require an additional query.

    Can't say what you may have did wrong without seeing what you did.
    Always use [code][/code] tags when posting code.

  4. #34
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by DataMiser View Post
    The place to put it depends on where and how you want to display it.

    Like I said you already have it there in that one piece of script you showed. You can assign it to a variable that you will use later in the script, just have to make sure you have the right scope on the variable or you can use a query and get it where you need it either will work with the variable being the faster since it does not require an additional query.


    Can't say what you may have did wrong without seeing what you did.
    Hi and again thanks for your reply :-) I'm not even sure I can do what I want but here are my thoughts with what I see as being the information I want to use.....

    This bit of script is in category_adit.asp. The code displays a form that allows you to enter a new category name and assigns it a selected colour which is predefined and stored in the LinkColor db form. It then hands over information to the category_add.asp script which then displays the message ... category ‘xyz’ has been added. which was the very first problem I had...

    Code:
    Dim Shade
    Dim LinkColorRS
    Set LinkColorRS = Server.CreateObject("ADODB.Recordset")
    	LinkColorRS.Open "SELECT *  FROM LinkColor", Connect, 3, 3
    While (Not LinkColorRS.EOF)
        Response.Write "<option STYLE='color: " & LinkColorRS("ColorCode") & " !important' value='" & LinkColorRS("ColorCode") & "'"
    If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Response.Write "selected"
    	Response.Write">" & LinkColorRS("ColorName") & "</option>"
        LinkColorRS.MoveNext
    Wend
    	LinkColorRS.Close()
    	CategoryRS.Close()
    What I think I need to do is to create a variable called… ‘Shade’ for example and assign it the value given in the response.write”>”& LinkColorRS(“ColorName”) bit of script but I don’t know how to do that. Linkcolor contains the two fields of ColorName (text) and ColorCode(Hex)

    The code is in the wrong part of the software to display whit the new category so somehow I need to move that value aver to the category_add.asp. That’s where the new category is displayed. I really look forward to your reply...regards

    DA

  5. #35
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,845

    Re: VB Script will not remove modified data from Database

    You have to do it a bit differently. Response.Write has nothing to do with setting variables and you also do not want to do it inside an option tag as that would just make the code harder to read

    All you need to do is set the variable=the field but you need to do it only when it is the right field and in the right place.

    For example given what you have there you would add another If statement inside your loop just like the one you have but outside the <option> tags
    Code:
    Dim Shade
    Dim LinkColorRS
    Set LinkColorRS = Server.CreateObject("ADODB.Recordset")
    LinkColorRS.Open "SELECT *  FROM LinkColor", Connect, 3, 3
    While (Not LinkColorRS.EOF)
        If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Shade=LinkColorRS("ColorName")
        Response.Write "<option STYLE='color: " & LinkColorRS("ColorCode") & " !important' value='" & LinkColorRS("ColorCode") & "'"
        If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Response.Write "selected"
        Response.Write">" & LinkColorRS("ColorName") & "</option>"
        LinkColorRS.MoveNext
    Wend
    LinkColorRS.Close()
    CategoryRS.Close()
    Also notice the way I intended the code, this makes it much easier to read where as what you had posted has some lines indented that should not be and others not indented that should be making it hard to follow.

    Lines within a code block should be indented one step in from the outer portion of the block. Lines outside the block should not be indented. An indented line tells the reader that it must be in a block and causes them to look for that block also a line that is not indented may cause the reader to miss the block it is in just overall making it more time consuming and harder to read it correctly.


    Now of course if you are wanting to write the value using a different script what I showed will do you no good at all as that Var will not be in scope. You will either have to do a lookup in the actual script you want to use it in or store it in a session var so it has a global scope.
    Last edited by DataMiser; July 25th, 2013 at 04:01 PM.
    Always use [code][/code] tags when posting code.

  6. #36
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by DataMiser View Post
    You have to do it a bit differently. Response.Write has nothing to do with setting variables and you also do not want to do it inside an option tag as that would just make the code harder to read

    All you need to do is set the variable=the field but you need to do it only when it is the right field and in the right place.

    For example given what you have there you would add another If statement inside your loop just like the one you have but outside the <option> tags
    Code:
    Dim Shade
    Dim LinkColorRS
    Set LinkColorRS = Server.CreateObject("ADODB.Recordset")
    LinkColorRS.Open "SELECT *  FROM LinkColor", Connect, 3, 3
    While (Not LinkColorRS.EOF)
        If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Shade=LinkColorRS("ColorName")
        Response.Write "<option STYLE='color: " & LinkColorRS("ColorCode") & " !important' value='" & LinkColorRS("ColorCode") & "'"
        If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Response.Write "selected"
        Response.Write">" & LinkColorRS("ColorName") & "</option>"
        LinkColorRS.MoveNext
    Wend
    LinkColorRS.Close()
    CategoryRS.Close()
    Also notice the way I intended the code, this makes it much easier to read where as what you had posted has some lines indented that should not be and others not indented that should be making it hard to follow.

    Lines within a code block should be indented one step in from the outer portion of the block. Lines outside the block should not be indented. An indented line tells the reader that it must be in a block and causes them to look for that block also a line that is not indented may cause the reader to miss the block it is in just overall making it more time consuming and harder to read it correctly.


    Now of course if you are wanting to write the value using a different script what I showed will do you no good at all as that Var will not be in scope. You will either have to do a lookup in the actual script you want to use it in or store it in a session var so it has a global scope.
    Hiya and once again many thanks for your rapid reply. The advice you give me about code indentation is valuable... Maybe this is why I am finding it so hard to try and follow things. It seems like there is no real method in a lot of the original software. Now that you have shown me how to set the variable I understand that I cannot use it here despite the fact that this page of code defines all the required info.

    The rest of what you write is a mystery to me in all honesty. I don't know what you mean by ...scope... (the constraints of the code function perhaps?). I do understand what lookup means and I have been trying to do that with no success, I'm not sure about syntax and related variables across tables.

    The code as it stands works and all fields of the DB are populated correctly so in theory I suppose I can jump to the category_add.asp script that displays the Category name details gathered from category_edit.asp and then do a lookup on the value of the category ColorName??? but I don't think I can do that because I have to check a variable in the Itype table and cross reference that with the associated value in the LinkColor table requesting the associated ColorName.... or is my logic too complex.. or just mixed up ? Am I missing a very simple method or just lost again? It seems logical to extract the data as it is created but how you would move it in a session variable with global scope is way, way beyond me, I'm not even sure I grasp the concept of that yet.... Hmmm any words of wisdom ??

  7. #37
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,845

    Re: VB Script will not remove modified data from Database

    Scope refers to where the variable is available. For example a Var defined in a Sub is only available in that sub. A Var declared at the top of the code before any subs is available to all the subs in that module/class.

    ASP uses whats called Session vars which have a session scope, meaning they can be accessed from any script within the current user session and thus can be used to hold vars that need to be used by more than one script.

    As for the lookup, I went over this already you just do a simple Select From Where query to get the value from the database that matches the code you have. look back a few posts for more info.


    For example using a session var

    Code:
    If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Session("Shade")=LinkColorRS("ColorName")
    Elsewhere in your other script you would have

    Code:
    Response.Write(Session("Shade"))
    Nothing to it
    Last edited by DataMiser; July 25th, 2013 at 09:31 PM.
    Always use [code][/code] tags when posting code.

  8. #38
    Join Date
    Jul 2005
    Posts
    1,074

    Re: VB Script will not remove modified data from Database

    Also...
    You can pass variables values to an asp using arguments when you call it
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  9. #39
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by jggtz View Post
    Also...
    You can pass variables values to an asp using arguments when you call it
    Hi JG

    My category_asp
    I think I am getting confused as to what does what in which bit of code. This is the .asp file page where I add the new category, assign it a color and then hit the ADD button. So if I assign the name TEST with an associated color... RED, it then inserts that entry into the DB under the “Type” module. The color is however shown in hex… So what I see is….. TypeId=966…TypeName=TEST… TypeColor=#F00… which is perfectly correct.
    Is this not the ideal point to query the database? If it is, how do I translate hex into the corresponding text color name? Do I need some sort of ‘lookup’ table or is that what I already have in the contents of LinkColor? That’s the module which contains a list of colors that I determine and where I give both the hex and text values. It has no association with the final choice. How would I do that?
    Everything I see points back to this bit of code…. Is this where I use the session variable? I guess not because surely it would only return the hex value? If I SQLquery the DB it too would only return the Hex value again I guess. The “Type” module is the only place where these values are brought together and from there they are represented correctly on the calendar page.
    I may have given you the wrong information so am not quite sure which way to turn right now. For completeness it is the category_add page that displays the ‘Category xxx’ has been added’ and it is also the place where I want to add the color I’ve selected. The category_edit script allows me to take an existing category and change the Category Name and Category Color then resubmit it to and update the database.

    Code:
    <%  
    				 Dim LinkColorRS
    				 Set LinkColorRS = Server.CreateObject("ADODB.Recordset") LinkColorRS.Open "SELECT *  FROM LinkColor", Connect, 3, 3
      				 While (Not LinkColorRS.EOF)
       				 Response.Write "<option STYLE='color: " & LinkColorRS("ColorCode") & " !important' value='" & LinkColorRS("ColorCode") & "'>" & LinkColorRS("ColorName") & "</option>"
    LinkColorRS.MoveNext
    	Wend
    %>
    I understand what you have explained to me and now that I can see the construction it sort of makes sense so I will have a play and see what I can do with it and if I can make it work for other little bug fixes I would like to tackle. Again…. Many thanks for your continued help, I really appreciate it.

    DA
    Last edited by davida1956; July 26th, 2013 at 08:05 PM. Reason: additional info

  10. #40
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    I noted also that I am using Dreamweaver in split mode and when I look at just script mode the indentation is a little less mangled os will cut n paste from there :-)

  11. #41
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Sorry DataMiser I thought you were the same person as JG who also seems to be following the thread.... just a little confusing :-)

  12. #42
    Join Date
    Jul 2005
    Posts
    1,074

    Re: VB Script will not remove modified data from Database

    Not just me... believe me, there are many more that are following this thread and your advances in resolving the problem... but DataMiser, as always, is doing the right thing... good luck!
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  13. #43
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by jggtz View Post
    Not just me... believe me, there are many more that are following this thread and your advances in resolving the problem... but DataMiser, as always, is doing the right thing... good luck!
    Hi JG,

    makes the impossible seem Didn't Know my sort of issues would interest anybody else, obviously go that wrong too :-) Yes DM is one heck smart guy who makes the impossible to some, factual for many, a good teacher with loads of patience and dedication which is great to see. Are there many more like DM on this site?

    Regards DA

  14. #44
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by DataMiser View Post
    Scope refers to where the variable is available. For example a Var defined in a Sub is only available in that sub. A Var declared at the top of the code before any subs is available to all the subs in that module/class.

    ASP uses whats called Session vars which have a session scope, meaning they can be accessed from any script within the current user session and thus can be used to hold vars that need to be used by more than one script.

    As for the lookup, I went over this already you just do a simple Select From Where query to get the value from the database that matches the code you have. look back a few posts for more info.


    For example using a session var

    Code:
    If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Session("Shade")=LinkColorRS("ColorName")
    Elsewhere in your other script you would have

    Code:
    Response.Write(Session("Shade"))
    Nothing to it

    Hi DM .. haven't heard from you in a while and was wondering if my post got through to you as I replied to somebody else by mistake. I've tried some of the suggestions you gave me but without much joy, for example ColorName is not in the same table as CategoryColor. I'm a little confused right now but think my explanation of the situation is still pretty much the same as it was when I wrote to you 4 or 5 days ago.......

    I think I am getting confused as to what does what in which bit of code. This is the .asp file page where I add the new category, assign it a color and then hit the ADD button. So if I assign the name TEST with an associated color... RED, it then inserts that entry into the DB under the “Type” module. The color is however shown in hex… So what I see is….. TypeId=966…TypeName=TEST… TypeColor=#F00… which is perfectly correct.

    Is this not the ideal point to query the database? If it is, how do I translate hex into the corresponding text color name? Do I need some sort of ‘lookup’ table or is that what I already have in the contents of LinkColor? That’s the module which contains a list of colors that I determine and where I give both the hex and text values. It has no association with the final choice. How would I do that?

    Everything I see points back to this bit of code…. Is this where I use the session variable? I guess not because surely it would only return the hex value? If I SQLquery the DB it too would only return the Hex value again I guess. The “Type” module is the only place where these values are brought together and from there they are represented correctly on the calendar page.

    I may have given you the wrong information so am not quite sure which way to turn right now. For completeness it is the category_add page that displays the ‘Category xxx’ has been added’ and it is also the place where I want to add the color I’ve selected. The category_edit script allows me to take an existing category and change the Category Name and Category Color then resubmit it to and update the database.


    [code]
    <%
    Dim LinkColorRS
    Set LinkColorRS = Server.CreateObject("ADODB.Recordset") LinkColorRS.Open "SELECT * FROM LinkColor", Connect, 3, 3
    While (Not LinkColorRS.EOF)
    Response.Write "<option STYLE='color: " & LinkColorRS("ColorCode") & " !important' value='" & LinkColorRS("ColorCode") & "'>" & LinkColorRS("ColorName") & "</option>"
    LinkColorRS.MoveNext
    Wend
    %>
    [code/]

    I understand what you have explained to me and now that I can see the construction it sort of makes sense so I will have a play and see what I can do with it and if I can make it work for other little bug fixes I would like to tackle. Again…. Many thanks for your continued help, I really appreciate it...

  15. #45
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,845

    Re: VB Script will not remove modified data from Database

    I had not saw any more questions. Am not sure what the question is now. Assuming that the value you are wanting to display is in the field called ColorName then what i showed you should work see post #35 and #37
    Always use [code][/code] tags when posting code.

Page 3 of 8 FirstFirst 123456 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center