473,395 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Visual Basic 2010 equivalent of JavaScript numbered variable names

116 64KB
Hi

I tried to find this via Google but as you can see from the title, I can't get my head round the correct terms to search for.

The issue is as follows - this is an application I'm converting from javascript to VB so would like the direct solution rather than the 'array' solution if it's possible.

In javascript...
var myname = "Billy";
i = 4;
document.getElementById('name'+i).value = myname;
document.getElementById('namebox'+i).checked = true;

The first 2 lines are obviously easy in VB but what is the equivalent of the last 2 lines? I thought it was something like Me.Controls... but can't find a way to get that to work.

Many thanks!
Feb 15 '13 #1

✓ answered by Mikkeee

You're in the right spot!
Expand|Select|Wrap|Line Numbers
  1.     Private Function FindControl(ByVal controlName As String) As Control
  2.         For Each ctrl As Control In Me.Controls
  3.             If ctrl.Name = controlName Then
  4.                 Return ctrl
  5.             End If
  6.         Next
  7.     End Function
  8.  
OR
Expand|Select|Wrap|Line Numbers
  1. ' Returns control array of matches
  2. Dim ctrl() As Control = Me.Controls.Find(controlName , True)
  3.  

4 1314
Mikkeee
94 64KB
You're in the right spot!
Expand|Select|Wrap|Line Numbers
  1.     Private Function FindControl(ByVal controlName As String) As Control
  2.         For Each ctrl As Control In Me.Controls
  3.             If ctrl.Name = controlName Then
  4.                 Return ctrl
  5.             End If
  6.         Next
  7.     End Function
  8.  
OR
Expand|Select|Wrap|Line Numbers
  1. ' Returns control array of matches
  2. Dim ctrl() As Control = Me.Controls.Find(controlName , True)
  3.  
Feb 15 '13 #2
robertybob
116 64KB
Many thanks, Mikkeee!

I managed to work through your thinking and have a partial success. The issue now is that, whilst my Label text is processed, it doesn't like the checkbox code. It throws a Checkbox is not a member of Systems.Forms etc.

A simplified version of my code is as follows - the checkbox control fails the build. The form contains Label1, Label2, Checkbox1 and Checkbox2.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  3.         Dim xx = 1
  4.         Dim thislabel = "Label" & xx
  5.         Dim thisbox = "Checkbox" & xx
  6.         Me.Controls(thislabel).Text = "New Text"  'perfect
  7.         Me.Controls(thisbox).Checked = True     ' fails
  8.     End Sub
  9. End Class
  10.  
All the best.
Feb 15 '13 #3
Mikkeee
94 64KB
Expand|Select|Wrap|Line Numbers
  1. DirectCast(Me.Controls(thisbox), CheckBox).Checked = True
  2.  
Feb 15 '13 #4
robertybob
116 64KB
Fantastic - thanks again, Mikkeee.
Feb 15 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Robin Powers | last post by:
PROCESS CONTROLS/VISUAL BASIC PROGRAMMERS SALARY: TO $100,000 LOCATION: LOS ANGELES AREA Our Client has recently acquired process automation systems used to monitor and control their...
1
by: Florin | last post by:
Hi, How to return a variable from javaScript to the visual basic? The script is loaded into the webbrowser control as a html page. THX
4
by: Jas | last post by:
Hi All I guess I should just have tried this to see if it works but I don't have access to a machine running IIS and can't test it and I am itching for an answer. I want to use dynamic...
0
by: Tech | last post by:
In Visual Basic 6.0, the Locked property of a ComboBox control determined whether the text-box portion of the control could be edited. In Visual Basic ..NET, the Locked property prevents a control...
2
by: Hamish Symington | last post by:
Hello, I'm trying to re-code a site which I wrote in PHP into ASP.NET using Visual Basic .NET. Something PHP has which has proved invaluable is the concept of variable variables. I haven't...
25
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For...
4
by: loopyloulilly | last post by:
Hi, Can somebody tell me the difference between vb.net and JavaScript? Thanks.
7
by: rmurgia | last post by:
When a variable is created using Javascript, should it then be able to be read immediately using embedded VB code or does the submit command have to be entered or are the variables between...
2
by: Johnny Wong | last post by:
Hi, I am new to visual basic. In my vb system, there is a dynamic datagrid to represent different reocrds in our database. Today I am gonna export the data to Excel file. I found most examples code...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.