locked
Using a Variable as a variable to a form ID RRS feed

  • Question


  • I'm breaking grounds into VB.NET. I've spent my life programming in PHP and i'm finding major differences in structures.
    I want to use a variable to reference the Text box

    Example:

    Fields = Array (Table Field names)

    pinfo = Array(Field Values of the widget)
      For Each Lbl In Fields
        Select Case Lbl
         Case "Field1",
           "Field2",
           "Field6",
          If pinfo(0)(Lbl).Equals(True) Then
           Lbl.Checked = True
          End If
          Default
          Lbl.Text = pinfo(0)(Lbl).ToString()
        End Select
    
       Next
    

    Is this possible?

    • Changed type BBabb Wednesday, June 29, 2011 6:03 PM wrong post
    • Moved by Kee Poppy Wednesday, July 6, 2011 3:49 AM (From:Visual Basic General)
    Wednesday, June 29, 2011 4:59 PM

Answers

  • Never mind found it using the FindControl()

    Thanks.

      Private Sub Manage_Printer(ByVal id As Integer)
        If id <> 0 Then
          Dim Fields As ArrayList = SQLTool.Get_Columns("Printers")
          Dim r_query As String = "select * from Printers where ID=" + id.ToString()
          Dim results As DataTable = SQLTool.Data_Table(r_query)
          Dim pinfo As ArrayList = New ArrayList(results.Rows.Count)
          For Each dr In results.Rows
            pinfo.Add(dr)
          Next
          For Each Lbl In Fields
            Select Case Lbl
              Case "PrinterCanSingleStitch",
                 "PrinterCanDualStitch",
                 "PrinterCanPerfectBind",
                 "PrinterCanSaddleStitch",
                 "PrinterCanOffsetStack",
                 "PrinterContinuous",
                 "PrinterHasStacker"
                If pinfo(0)(Lbl) = True Then
                  Dim P As CheckBox = PForm.FindControl(Lbl)
                  P.Checked = True
                End If
              Case "PrinterStatus",
                 "PrinterWorkType"
                Dim P As DropDownList = PForm.FindControl(Lbl)
                P.Items.Add("online")
                P.Items.Add("Offline")
              Case Else
                Response.Write(Lbl + "<br>")
    
            End Select
          Next
        Else
          PrintManager_Label.Text = "<h2>Select Printer from Left Menu</h2>"
        End If
      End Sub
    
    


    • Marked as answer by Kee Poppy Wednesday, July 6, 2011 3:48 AM
    Wednesday, June 29, 2011 6:29 PM

All replies

  • I'm a little unclear as to what you're trying to do. You say textboxes in your explanation but you have checkboxes in your example. Can you clarify what it is you are trying to do?

     

    Thanks.

     

     

     

    Wednesday, June 29, 2011 5:35 PM
  • If this is an ASP.NET or VBScript embedded in Webpage question, you've got the wrong Forum.

    Beyond that, your code is entirely theoretical and also totally nonfunctional; you didn't cut/paste this out of any working or semi-working code file.

    So the answer to your question is yes, a TextBox is in fact a variable so you can reference it like anything else.  But no, you can't do that using code you made up off the top of your head that doesn't compile.


    It never hurts to try. In a worst case scenario, you'll learn from it.
    Wednesday, June 29, 2011 5:37 PM
  • Below is the total script.  Basically instead of using a DataGrid, or GridView i'm building the Form.  Without having to do each form field manually in PHP i could do this dynamically, I am hoping to do this in VB.NET as well.

     

     
     Private Sub Manage_Printer(ByVal id As Integer)
      If id <> 0 Then
       Dim Fields As ArrayList = SQLTool.Get_Columns("Printers")
       Dim r_query As String = "select * from Printers where ID=" + id.ToString()
       Dim results As DataTable = SQLTool.Data_Table(r_query)
       Dim pinfo As ArrayList = New ArrayList(results.Rows.Count)
       For Each dr In results.Rows
        pinfo.Add(dr)
       Next
       For Each Lbl In Fields
        Select Case Lbl
         Case "PrinterCanSingleStitch",
           "PrinterCanDualStitch",
           "PrinterCanPerfectBind",
           "PrinterCanSaddleStitch",
           "PrinterCanOffsetStack",
           "PrinterContinuous",
           "PrinterHasStacker"
          If pinfo(0)(Lbl).Equals(True) Then
           Lbl.Checked = True
          End If
         Case Else
          Lbl.Text = pinfo(0)(Lbl).ToString()
        End Select
       Next
      Else
       PrintManager_Label.Text = "<h2>Select Printer from Left Menu</h2>"
      End If
     End Sub



    Form:

     

        
    <table>
         <tr>
          <td>
           Printer
          </td>
          <td>
           <asp:TextBox ID="PrinterName" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           ID
          </td>
          <td>
           <asp:Label ID="PID" runat="server"></asp:Label>
          </td>
         </tr>
         <tr>
          <td>
           Last Access
          </td>
          <td>
           <asp:Label ID="PrinterLastAccess" runat="server"></asp:Label>
          </td>
         </tr>
         <tr>
          <td>
           Current Pages
          </td>
          <td>
           <asp:Label ID="PrinterCurrentPages" runat="server"></asp:Label>
          </td>
         </tr>
         <tr>
          <td>
           Threshold
          </td>
          <td>
           <asp:TextBox ID="PrinterThreshold" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Work Type
          </td>
          <td>
           <asp:DropDownList ID="PrinterWorkType" runat="server"></asp:DropDownList>
          </td>
         </tr>
         <tr>
          <td>
           MFG
          </td>
          <td>
           <asp:TextBox ID="PrinterManufacturer" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Printer Speed Hourly A4
          </td>
          <td>
           <asp:TextBox ID="PrinterSpeedHourlyA4" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Single Stitch
          </td>
          <td>
           <asp:CheckBox ID="PrinterCanSingleStitch" runat="server"></asp:CheckBox>
          </td>
         </tr>
         <tr>
          <td>
           Dual Stitch
          </td>
          <td>
           <asp:CheckBox ID="PrinterCanDualStitch" runat="server"></asp:CheckBox>
          </td>
         </tr>
         <tr>
          <td>
           Perfect Bind
          </td>
          <td>
           <asp:CheckBox ID="PrinterCanPerfectBind" runat="server"></asp:CheckBox>
          </td>
         </tr>
         <tr>
          <td>
           Perfect Bind Max
          </td>
          <td>
           <asp:TextBox ID="PrinterPerfectBindSheetMax" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Saddle Stitch
          </td>
          <td>
           <asp:CheckBox ID="PrinterCanSaddleStitch" runat="server"></asp:CheckBox>
          </td>
         </tr>
         <tr>
          <td>
           Saddle Stitch Bind Max
          </td>
          <td>
           <asp:TextBox ID="PrinterSaddleStitchSheetMax" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Can Offset Stack
          </td>
          <td>
           <asp:CheckBox ID="PrinterCanOffsetStack" runat="server"></asp:CheckBox>
          </td>
         </tr>
         <tr>
          <td>
           Hourly Max Pages
          </td>
          <td>
           <asp:TextBox ID="PrinterHourlyMaxPages" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Continuous
          </td>
          <td>
           <asp:CheckBox ID="PrinterContinuous" runat="server"></asp:CheckBox>
          </td>
         </tr>
         <tr>
          <td>
           Has Stacker
          </td>
          <td>
           <asp:CheckBox ID="PrinterHasStacker" runat="server"></asp:CheckBox>
          </td>
         </tr>
         <tr>
          <td>
           Max Size
          </td>
          <td>
           <asp:TextBox ID="PrinterMaxSize" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Status
          </td>
          <td>
           <asp:DropDownList ID="PrinterStatus" runat="server"></asp:DropDownList>
          </td>
         </tr>
         <tr>
          <td>
           IPAddress
          </td>
          <td>
           <asp:TextBox ID="PrinterIPAddress" runat="server" CssClass="ip"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Queue Name
          </td>
          <td>
           <asp:TextBox ID="PrinterQueue" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Stitch Max
          </td>
          <td>
           <asp:TextBox ID="PrinterStitchMax" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Operator Assigned ID
          </td>
          <td>
           <asp:TextBox ID="PrinterOperatorAssignedID" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Operator Last Name
          </td>
          <td>
           <asp:TextBox ID="PrinterOperatorAssignedLastName" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Min Qty
          </td>
          <td>
           <asp:TextBox ID="PrinterMinQty" runat="server"></asp:TextBox>
          </td>
         </tr>
         <tr>
          <td>
           Max Qty
          </td>
          <td>
           <asp:TextBox ID="PrinterMaxQty" runat="server"></asp:TextBox>
          </td>
         </tr>
        </table>
    



     


    Wednesday, June 29, 2011 5:56 PM
  • Never mind found it using the FindControl()

    Thanks.

      Private Sub Manage_Printer(ByVal id As Integer)
        If id <> 0 Then
          Dim Fields As ArrayList = SQLTool.Get_Columns("Printers")
          Dim r_query As String = "select * from Printers where ID=" + id.ToString()
          Dim results As DataTable = SQLTool.Data_Table(r_query)
          Dim pinfo As ArrayList = New ArrayList(results.Rows.Count)
          For Each dr In results.Rows
            pinfo.Add(dr)
          Next
          For Each Lbl In Fields
            Select Case Lbl
              Case "PrinterCanSingleStitch",
                 "PrinterCanDualStitch",
                 "PrinterCanPerfectBind",
                 "PrinterCanSaddleStitch",
                 "PrinterCanOffsetStack",
                 "PrinterContinuous",
                 "PrinterHasStacker"
                If pinfo(0)(Lbl) = True Then
                  Dim P As CheckBox = PForm.FindControl(Lbl)
                  P.Checked = True
                End If
              Case "PrinterStatus",
                 "PrinterWorkType"
                Dim P As DropDownList = PForm.FindControl(Lbl)
                P.Items.Add("online")
                P.Items.Add("Offline")
              Case Else
                Response.Write(Lbl + "<br>")
    
            End Select
          Next
        Else
          PrintManager_Label.Text = "<h2>Select Printer from Left Menu</h2>"
        End If
      End Sub
    
    


    • Marked as answer by Kee Poppy Wednesday, July 6, 2011 3:48 AM
    Wednesday, June 29, 2011 6:29 PM
  • For future reference, you need the ASP.NET Forums.
    It never hurts to try. In a worst case scenario, you'll learn from it.
    Wednesday, June 29, 2011 6:34 PM