Click here to Skip to main content
15,899,935 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionHow to implement component class in vb Pin
TianYang20-May-03 15:27
TianYang20-May-03 15:27 
Generalvarible in shell Pin
bamnet20-May-03 11:16
bamnet20-May-03 11:16 
GeneralRe: varible in shell Pin
Ray Cassick20-May-03 12:10
Ray Cassick20-May-03 12:10 
GeneralRe: varible in shell Pin
Nick Seng20-May-03 15:57
Nick Seng20-May-03 15:57 
GeneralAbout custom-drawn linklabel controls Pin
Chopper20-May-03 5:02
Chopper20-May-03 5:02 
GeneralRe: About custom-drawn linklabel controls Pin
Ray Cassick20-May-03 6:15
Ray Cassick20-May-03 6:15 
GeneralRe: About custom-drawn linklabel controls Pin
Chopper20-May-03 22:38
Chopper20-May-03 22:38 
GeneralConversion from C# to VB.NET Pin
lasseran20-May-03 4:16
lasseran20-May-03 4:16 
Hi,

I have tried to convert an C# sample program to VB.Net but was confronted with one problem. This sample describes adding controls dynamically to a placeholder and reading back their values after user clicks a button. You can see the whole C# source here.

I think I have managed to do all the other conversion but following snippet of C# code is problem. Confused | :confused:

(I have removed the comments)

XPathDocument surveyDoc = new XPathDocument(Server.MapPath("ExSurvey.xml"));
XPathNodeIterator itr = surveyDoc.CreateNavigator().Select("//question");
System.Text.StringBuilder sb;
sb = new System.Text.StringBuilder();
sb.Append("Survey submitted on " + DateTime.Now + Environment.NewLine);
while (itr.MoveNext()) {
  string controlName = itr.Current.GetAttribute("name", "");
  sb.Append(controlName);
  sb.Append(" : ");
  object ctrl = FindControl(controlName);
    if (ctrl is TextBox) {
      sb.Append(((TextBox)ctrl).Text);
    }
    if (ctrl is RadioButtonList) {
      if (((RadioButtonList)ctrl).SelectedItem != null) {
        sb.Append(((RadioButtonList)ctrl).SelectedItem.Value);
      }
    }
  sb.Append(Environment.NewLine);
}
string body = sb.ToString();


This code returns the ID of the control and it's value in body. That's what I'm after.

My effort in translating this snippet was as follows:

Dim surveyDoc As XPathDocument = New XPathDocument(Server.MapPath("ExSurvey.xml"))
Dim itr As XPathNodeIterator = surveyDoc.CreateNavigator().Select("//question")
Dim sb As System.Text.StringBuilder
sb = New System.Text.StringBuilder()
sb.Append("Survey submitted on " + DateTime.Now + "<br>")
While (itr.MoveNext())
  Dim controlName As String = itr.Current.GetAttribute("name", "")
  sb.Append(controlName)
  sb.Append(" : ")
  Dim ctrl As Object = FindControl(controlName)
  If (TypeOf ctrl Is TextBox) Then
    Dim myTextBox As New TextBox()
    myTextBox = ctrl
    sb.Append(myTextBox.Text + "<br>")
  End If
  If (TypeOf ctrl Is RadioButtonList) Then
    Dim myRadioButtonList As New TextBox()
    myRadioButtonList = ctrl
    If (Not myRadioButtonList.SelectedItem Is Nothing) Then
      sb.Append(myRadioButtonList.SelectedItem.Value.ToString + "<br>")
    End If
  End If
  sb.Append("<br>")
End While
Dim body As String = sb.ToString()


To my disappointment my body contains only the ID and the semicolon, not the value of the control. Cry | :((

If somebody is kind enough and tells to me what is wrong in my code, I would be ever grateful to that person. I know that is not much in this cyberworld but anyway...

Lasse Rantanen
GeneralRe: Conversion from C# to VB.NET Pin
The Limey21-May-03 22:22
The Limey21-May-03 22:22 
GeneralVB6 Currency conversion to .NET Pin
dazinith20-May-03 3:53
dazinith20-May-03 3:53 
GeneralRe: VB6 Currency conversion to .NET Pin
J. Dunlap20-May-03 7:55
J. Dunlap20-May-03 7:55 
GeneralRe: VB6 Currency conversion to .NET Pin
dazinith20-May-03 8:09
dazinith20-May-03 8:09 
GeneralLooking for Good, Concise C++ Tutorials Pin
Kevin McFarlane20-May-03 1:35
Kevin McFarlane20-May-03 1:35 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
Nick Seng20-May-03 15:50
Nick Seng20-May-03 15:50 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
Kevin McFarlane21-May-03 0:40
Kevin McFarlane21-May-03 0:40 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
Nick Seng21-May-03 3:07
Nick Seng21-May-03 3:07 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
Kevin McFarlane21-May-03 5:09
Kevin McFarlane21-May-03 5:09 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
Nick Seng21-May-03 5:43
Nick Seng21-May-03 5:43 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
Ray Cassick20-May-03 17:32
Ray Cassick20-May-03 17:32 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
Ray Cassick20-May-03 17:34
Ray Cassick20-May-03 17:34 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
Kevin McFarlane21-May-03 0:49
Kevin McFarlane21-May-03 0:49 
GeneralVB and Activex Control Pin
hajer19-May-03 23:16
hajer19-May-03 23:16 
GeneralcdWord Application Pin
Member 35075519-May-03 23:08
Member 35075519-May-03 23:08 
GeneralVB PRINTER OBJECT PROBLEM Pin
Cheickna18-May-03 22:50
Cheickna18-May-03 22:50 
GeneralNeed tutor in Seattle Area Pin
Shelia Proby18-May-03 13:43
Shelia Proby18-May-03 13:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.