Results 1 to 5 of 5

Thread: Need Some Help Please

  1. #1
    New Member
    Join Date
    Jul 12
    Posts
    3

    Need Some Help Please

    Hi everyone,

    I would really appreciate some help on this code that I am working on for work.

    This code records and investors stock choice, the direction they think it will go, and thier rationale. Once the inputs entered theya re submitted to a table in the lower portion of the HTA, and the data in those rows is then exported to a CSV file.

    I am having two problems:

    1. In each row in the last coloumn there is an "End" button which, when pushed, I would like to see it delete the row it is contained in. Currently, it only deltes the last row enetered. How would I configure it so that when it is click it deltes the row that it is in?
    2. Just as every entry is submitted to a CSV I would like to configure the clicking of the "End" button to submit the data in the row that it is contained in to the CSV file before the row is deleted. How would i go about doing that?

    Here is the code for your reference:

    Code:
    <html>
    <head>
    <title>Execution Alpha</title>
     <HTA:APPLICATION ID="oHTA"
        APPLICATIONNAME="StockPredictions"
        Border = "thin"
        Borderstyle = "complex"
       >
    <script language="VBScript">
    
    count=1 'setting counter
    
    ''''''''''''''''''''''''Window Sizing'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Sub StartUp() 
       Dim x,y 
       x = (window.screen.width - 500) / 2 
       y = (window.screen.height - 300) / 2 
       If x < 0 Then x = 0 
       If y < 0 Then y = 0 
       window.resizeTo 500,300 
       window.moveTo x,y 
    End Sub 
    StartUp 
    
    ''''''''''''''''''''''''Table set up'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    sub checkEnter()
       if window.event.keyCode = 13 then
       runTogether()
       end if
    end sub
    
    sub runTogether()
       confirm()
       doAddRow()
       writeToFile()
       start()
    end sub
    
    sub confirm()
    
       if Prediction(0).checked then
          Selection = "Up"
       end if
    
       if Prediction(1).Checked then
          Selection = "Down"
       end if
    
       Dim oWNet : Set oWNet = CreateObject("WScript.Network")''''''''''''''''''''''' get username''''''''''''''''''''''''''''''''''''''''''''''
    
       'if Symbol.value <> "" then
       '   msgBox "You entered " & Symbol.value & " and predict that the stock will go " & Selection, 64, "Input" '''' test reciept of input
       'end if
    
    end sub
    
    Sub doAddRow()
    
       if Prediction(0).checked then
          Selection = "Up"
       end if
    
       if Prediction(1).Checked then
          Selection = "Down"
       end if
    
       if Symbol.value <> "" then
          Dim oTbl, oRow, oCell
          Set oTbl=document.getElementById("mytable")
          Set oRow = oTbl.insertRow 
          Set oCell = oRow.insertCell
          oCell.innerHTML= Symbol.value
          Set oCell = oRow.insertCell
          oCell.innerHTML =Selection
          Set oCell = oRow.insertCell
          oCell.innerHTML= Time()
          Set oCell = oRow.insertCell
          oCell.innerHTML= DropDown2.Value
          Set oCell = oRow.insertCell
          oCell.innerHTML= "<input name = 'end' type = 'button' value = 'End' onclick = 'deleteRow()'/>"
       else
          msgBox "You did not enter a symbol!"
       end if
    
       count = count+1
    
    End sub 
    
    
    ''''''''''''''''''''''''Delete selections'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Sub deleteRow()
    
       Dim oTbl, oRow
       Set oTbl=document.getElementById("mytable")
       if count>2 then
       oTbl.deleteRow()
    
       count = count -1
    
       end if
    
    
    End Sub
    
    
    ''''''''''''''''''''''''Start and End''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    dim startEnd
       startEnd = "Start"
    
    sub start()
    
       startEnd = "Start"
       
    end sub
    
    'sub end()
    
    '   startEnd = "End"
    
    'end sub
    
    
    ''''''''''''''''''''''''Write to file''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    sub writeToFile()
    
       if Prediction(0).checked then
          Selection = "Up"
       end if
    
       if Prediction(1).Checked then
          Selection = "Down"
       end if
    
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      filename = "G:\ExecutionAlpha\pred.csv"
      If objFSO.FileExists(filename) Then
           Dim oWNet : Set oWNet = CreateObject("WScript.Network")
           Set objFile = objFSO.OpenTextFile(filename, 8)
           strLine = oWNet.UserName & " , " & startEnd & " , " & Symbol.value &  " , " & Selection & " , " &  Now() & " , " & DropDown2.Value
           objFile.WriteLine strLine
           objFile.Close
      end if
    end sub
    
    
    ''''''''''''''''''''''''GUI''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    </script>
    
    <style>  
     BODY {
            background-color: buttonface;
            margin-top: 10px;`
            margin-left: 20px;
            margin-right: 20px;
            margin-bottom: 5px;
            font-family: arial,sans-serif;
            font-size: 10pt;
     
     }
    
     .button {
            width: 91px;
            height: 25px;
            font-family: arial,sans-serif;
            font-size: 8pt;
     }
     td {
            font-family: arial,sans-serif;
            font-size: 10pt;
            
     }                     
     #scroll {
         height:100%;
         overflow:auto;
     }
     SELECT.FixedWidth  {
      width: 17em;  /* maybe use px for pixels or pt for points here */
     }   
     </style>
    
    </head>
    <body bgcolor="#FFFFFF">
    
    <left>
       <table align="center" width="100%" id="mytable2" border='1'>
          <tr>
    	<td>Symbol</td><td>Direction</td><td>Rationale</tr>
          <tr>
          <TD> <input name="Symbol" type="text" id="Symbol" onKeyPress = "checkEnter()" /></TD>
          <TD> <input checked name = "Prediction" type = "radio"  value = "0"> Up
               <input name = "Prediction" type = "radio"  value = "1"> Down
          <TD>  
      <select size="1" name="DropDown2"> 
      <option value="Market Flows">Market Flows&nbsp&nbsp&nbsp&nbsp&nbsp</option> 
      <option value="Directional View">Directional View</option> 
      </select> 
    
     </table>
    
    <center>
    <br>
    <TABLE>
    <TR>
    <INPUT TYPE="button" value="Enter" onClick = "runTogether()"> 
    </TABLE>     
    <p>
    
    <b>Open calls</b>
       <table width = "100%" id="mytable" border='1'>         
          <tr><td>Symbol</td><td>Direction</td><td>Time</td><td>Rationale</td><td>End</td></tr>
          <tr>
       </table>
    
    </body>
    </html>
    Dont forget to change the export directory or you will get an error.

    Thanks for your help.... (I just started with VBScript and this porject is needed tomorrow at 8 AM!! )

    obang

  2. #2
    New Member
    Join Date
    Jul 12
    Posts
    3

    Re: Need Some Help Please

    OK so I have an enxtension on this assignment... I was wondering, is there a way when you push a button that is contained in a row that it returns the row number that it is in?

    In that way i can just take that number and pass it through the row delete function.

  3. #3
    PowerPoster
    Join Date
    Jun 01
    Location
    Trafalgar, IN
    Posts
    3,479

    Re: Need Some Help Please

    I have never worked with an hta file before so there is probably a much better way of doing the but this seems to allow you to delete the proper row.

    I made updates to the doAddRow and deleteRow methods.

    Code:
    <html>
    <head>
    <title>Execution Alpha</title>
     <HTA:APPLICATION ID="oHTA"
        APPLICATIONNAME="StockPredictions"
        Border = "thin"
        Borderstyle = "complex"
       >
    <script language="VBScript">
    
    count=1 'setting counter
    
    ''''''''''''''''''''''''Window Sizing'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Sub StartUp() 
       Dim x,y 
       x = (window.screen.width - 500) / 2 
       y = (window.screen.height - 300) / 2 
       If x < 0 Then x = 0 
       If y < 0 Then y = 0 
       window.resizeTo 500,300 
       window.moveTo x,y 
    End Sub 
    StartUp 
    
    ''''''''''''''''''''''''Table set up'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    sub checkEnter()
       if window.event.keyCode = 13 then
       runTogether()
       end if
    end sub
    
    sub runTogether()
       confirm()
       doAddRow()
       writeToFile()
       start()
    end sub
    
    sub confirm()
    
       if Prediction(0).checked then
          Selection = "Up"
       end if
    
       if Prediction(1).Checked then
          Selection = "Down"
       end if
    
       Dim oWNet : Set oWNet = CreateObject("WScript.Network")''''''''''''''''''''''' get username''''''''''''''''''''''''''''''''''''''''''''''
    
       'if Symbol.value <> "" then
       '   msgBox "You entered " & Symbol.value & " and predict that the stock will go " & Selection, 64, "Input" '''' test reciept of input
       'end if
    
    end sub
    
    Sub doAddRow()
    
       if Prediction(0).checked then
          Selection = "Up"
       end if
    
       if Prediction(1).Checked then
          Selection = "Down"
       end if
    
        Dim strButton
        strButton = "<input name = 'endCOUNT' type = 'button' value = 'End' onclick = 'deleteRow(COUNT)'/>"
        strButton = Replace(strButton, "COUNT", count)
        
       if Symbol.value <> "" then
          Dim oTbl, oRow, oCell
          Set oTbl=document.getElementById("mytable")
          Set oRow = oTbl.insertRow 
          Set oCell = oRow.insertCell
          oCell.innerHTML= Symbol.value
          Set oCell = oRow.insertCell
          oCell.innerHTML =Selection
          Set oCell = oRow.insertCell
          oCell.innerHTML= Time()
          Set oCell = oRow.insertCell
          oCell.innerHTML= DropDown2.Value
          Set oCell = oRow.insertCell
          oCell.innerHTML= strButton
       else
          msgBox "You did not enter a symbol!"
       end if
    
       count = count+1
    
    End sub 
    
    
    ''''''''''''''''''''''''Delete selections'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Sub deleteRow(row)
    
       Dim oTbl, oRow
       Set oTbl=document.getElementById("mytable")
       Dim cinput
       Dim indx
       
       indx = 1
        set cinput=document.getElementsByTagName("input")
        for i=0 to cinput.length-1
            if cinput(i).type="button" then
                if instr(cinput(i).name, "end") then
                    indx = indx + 1
                    if cinput(i).name = "end" & row then
                        exit for
                    end if
                end if
            end if
        next
    
    
       if indx > 1 then
        oTbl.deleteRow(indx)
       end if
    
    
    End Sub
    
    
    ''''''''''''''''''''''''Start and End''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    dim startEnd
       startEnd = "Start"
    
    sub start()
    
       startEnd = "Start"
       
    end sub
    
    'sub end()
    
    '   startEnd = "End"
    
    'end sub
    
    
    ''''''''''''''''''''''''Write to file''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    sub writeToFile()
    
       if Prediction(0).checked then
          Selection = "Up"
       end if
    
       if Prediction(1).Checked then
          Selection = "Down"
       end if
    
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      filename = "C:\Documents and Settings\Mark\Desktop\pred.csv"
      If objFSO.FileExists(filename) Then
           Dim oWNet : Set oWNet = CreateObject("WScript.Network")
           Set objFile = objFSO.OpenTextFile(filename, 8)
           strLine = oWNet.UserName & " , " & startEnd & " , " & Symbol.value &  " , " & Selection & " , " &  Now() & " , " & DropDown2.Value
           objFile.WriteLine strLine
           objFile.Close
      end if
    end sub
    
    
    ''''''''''''''''''''''''GUI''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    </script>
    
    <style>  
     BODY {
            background-color: buttonface;
            margin-top: 10px;`
            margin-left: 20px;
            margin-right: 20px;
            margin-bottom: 5px;
            font-family: arial,sans-serif;
            font-size: 10pt;
     
     }
    
     .button {
            width: 91px;
            height: 25px;
            font-family: arial,sans-serif;
            font-size: 8pt;
     }
     td {
            font-family: arial,sans-serif;
            font-size: 10pt;
            
     }                     
     #scroll {
         height:100%;
         overflow:auto;
     }
     SELECT.FixedWidth  {
      width: 17em;  /* maybe use px for pixels or pt for points here */
     }   
     </style>
    
    </head>
    <body bgcolor="#FFFFFF">
    
    <left>
       <table align="center" width="100%" id="mytable2" border='1'>
          <tr>
    	<td>Symbol</td><td>Direction</td><td>Rationale</tr>
          <tr>
          <TD> <input name="Symbol" type="text" id="Symbol" onKeyPress = "checkEnter()" /></TD>
          <TD> <input checked name = "Prediction" type = "radio"  value = "0"> Up
               <input name = "Prediction" type = "radio"  value = "1"> Down
          <TD>  
      <select size="1" name="DropDown2"> 
      <option value="Market Flows">Market Flows&nbsp&nbsp&nbsp&nbsp&nbsp</option> 
      <option value="Directional View">Directional View</option> 
      </select> 
    
     </table>
    
    <center>
    <br>
    <TABLE>
    <TR>
    <INPUT TYPE="button" value="Enter" onClick = "runTogether()"> 
    </TABLE>     
    <p>
    
    <b>Open calls</b>
       <table width = "100%" id="mytable" border='1'>         
          <tr><td>Symbol</td><td>Direction</td><td>Time</td><td>Rationale</td><td>End</td></tr>
          <tr>
       </table>
    
    </body>
    </html>

  4. #4
    New Member
    Join Date
    Jul 12
    Posts
    3

    Re: Need Some Help Please

    Wow! Thanks so much! You really helped me out with your editing!

    If you have the time could you please help me out with this one last problem:

    Every time the "Enter" key is hit, the data is submitted to a CSV file, is it possible that when the "End" key for its assocaited row is clicked that it then again submits the stock symbol, direction, rationale, and time that the end key was pressed? The Idea being that if a trader puts in Symbol: "IBM" Direction: "Up" Rationale: "Market Flows" that entry then gets written to the CSV file with a time stamp. When the trader pushes "End" in one of the rows the data in that row should be sent to the CSV with the time stamp for when the call was ended.

    Right now it is only set up that pushing the "Enter" key writes data to the CSV, but I am trying to configure the code so that "End" also writes the row data to the CSV. Any thoughts on this?

    Thanks again for helping me out! (Just started learning VBScript 4 days ago)....

  5. #5
    PowerPoster
    Join Date
    Jun 01
    Location
    Trafalgar, IN
    Posts
    3,479

    Re: Need Some Help Please

    This should get you the values of the row being deleted. I think you can figure out how to write them to your file during the delete process.
    Code:
    Sub deleteRow(row)
    
       Dim oTbl, oRow
       Set oTbl=document.getElementById("mytable")
       Dim cinput
       Dim indx
       
       indx = 1
        set cinput=document.getElementsByTagName("input")
        for i=0 to cinput.length-1
            if cinput(i).type="button" then
                if instr(cinput(i).name, "end") then
                    indx = indx + 1
                    if cinput(i).name = "end" & row then
                        exit for
                    end if
                end if
            end if
        next
    
    
       if indx > 1 then
        MsgBox  oTbl.childNodes( 0 ).childNodes( indx ).childNodes( 0 ).innerText & vbCrLf & _
            oTbl.childNodes( 0 ).childNodes( indx ).childNodes( 1 ).innerText & vbCrLf & _
            oTbl.childNodes( 0 ).childNodes( indx ).childNodes( 2 ).innerText & vbCrLf & _
            oTbl.childNodes( 0 ).childNodes( indx ).childNodes( 3 ).innerText & vbCrLf & _
            oTbl.childNodes( 0 ).childNodes( indx ).childNodes( 4 ).innerText
        
        oTbl.deleteRow(indx)
       end if
    
    
    End Sub

Posting Permissions

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