473,395 Members | 1,937 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.

Use a string to represent a control name

Hi All,
Here my doubt is regarding to a picture box in VB 6.0

assume that i have few picture boxes in my appliaction named Picture1,picture2,picture3..etc.

And in my application, i have to load the pictures dynamically. i can load like...
Picture1.picture=Load picture("path of a .bmp)
Picture2.picture=Load picture("path of a .bmp)
Picture3.picture=Load picture("path of a .bmp)

But i am not interested to load like this. i want to write a method like this..

private sub subLoadPictures(byval pictrueName as string, byval PicturePath as string)
pictureName.picture=load picture(picturepath)
end sub

I tried this one, but could not get working properly.. could u please say how to use a string that represents the name of a picture.

Thanks:
regards:
raghunadhs.
Aug 17 '07 #1
3 1412
Robbie
180 100+
Hi All,
Here my doubt is regarding to a picture box in VB 6.0

assume that i have few picture boxes in my appliaction named Picture1,picture2,picture3..etc.

And in my application, i have to load the pictures dynamically. i can load like...
Picture1.picture=Load picture("path of a .bmp)
Picture2.picture=Load picture("path of a .bmp)
Picture3.picture=Load picture("path of a .bmp)

But i am not interested to load like this. i want to write a method like this..

private sub subLoadPictures(byval pictrueName as string, byval PicturePath as string)
pictureName.picture=load picture(picturepath)
end sub

I tried this one, but could not get working properly.. could u please say how to use a string that represents the name of a picture.

Thanks:
regards:
raghunadhs.
If you're using PictureBox controls, that's the type you should use for your sub.
Using your example:

private sub subLoadPictures(PictureObj as PictureBox, byval PicturePath as string)
PictureObj.picture=load picture(picturepath)
end sub

Notice also that I got rid of the ByVal. You probably shouldn't use that when referring to an actual object, rather than just a property of it. ;)
(I THINK that is true, at least)
Aug 19 '07 #2
Killer42
8,435 Expert 8TB
Thanks again, Robbie.

raghunadhs, you might be interested to know that you can refer to a control using a string as you suggested, by making use of the Controls collection. (Though normally you shouldn't need to). Assuming this code resides within a form (not a code module), you could have said:
Expand|Select|Wrap|Line Numbers
  1. Private Sub subLoadPicture(ByVal PictureName As String, ByVal PicturePath As String)
  2.   Me.Controls(PictureName).Picture = LoadPicture(PicturePath)
  3. end sub
A couple of things to consider...
  • Your terms are a bit confusing. PictureName is the name of a PictureBox control, not the actual "picture". I think you need to differentiate between the picture and the control that displays it.
  • It's probably better to just pass the control, as Robbie showed.
  • If you haven't already, I highly recommend that you learn about control arrays. They are very useful for this kind of thing.
Aug 20 '07 #3
Thanks again Killer, and thanks Robbie...
it is working. Killer... I am using the control arrays. But there are so many type of control arrays like picture1(0),picture2(0).. like that. I think you are familiar with my previous thread (drag and drop objects, in that example I am adding some more picture boxes).
For doing some experiments with that stuff I needed this type of common method which can represent a particular pictureBox, by taking picturebox name, and path as parameters.

Anyhow both of your examples have helped me a lot.

Thanks:
regards:
raghunahds

Thanks again, Robbie.

raghunadhs, you might be interested to know that you can refer to a control using a string as you suggested, by making use of the Controls collection. (Though normally you shouldn't need to). Assuming this code resides within a form (not a code module), you could have said:
Expand|Select|Wrap|Line Numbers
  1. Private Sub subLoadPicture(ByVal PictureName As String, ByVal
Aug 20 '07 #4

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

Similar topics

2
by: Steve | last post by:
I'm in a weird situation where I'm using ComboBox's in a DataGrid. When the ComboBox selection changes, I'm currently storing the SelectedValue object into the DataSource of the DataGrid cell. ...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
2
by: guoqi zheng | last post by:
We can enum to represent a interger using a string. But how can we use enum to represent string below is what I want to achieve. Public Enum country Netherlands = "nl" America = "US" France...
9
by: Joel Finkel | last post by:
Is there a way to execute a method if all we know is its name as a string? Let's say we have the following class. What is the code for the Execute method? I need a solution that works with the...
5
by: glenn | last post by:
Hi folks, The problem I have is that a query string works if hard-coded but if I pass a variable to it, it does not work as shown here. This works: querystring="SELECT * FROM USERS WHERE...
3
by: dotnetnoob | last post by:
i have two strings from xml file str1 = 800.7415_801.101_8.115_216.12 str2 = 800.7415_801.101_8.115_216.12_217.570 the first stream represent a xml file 800.7415_801.101_8.115_261.12.xml...
7
by: Malcolm | last post by:
This is a program to convert a text file to a C string. It is offered as a service to the comp.lang.c community. Originally I thought it would be a five minute job to program. In fact there are...
9
by: CapCity | last post by:
We're rewritting an app using C# 2005 and it needs to read files in netCDF format. A dll is available for this and we've had success in calling its functions, unless it updates strings. We have...
1
by: kellysgirl | last post by:
Now what you are going to see posted here is both the set of instructions I was given..and the code I have written. The instructions I was given are as follows In this case, you will create...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.