Edited 6 Years Ago by pankaj.garg: n/a
i am trying to create a program where user can add picture to a form at runtime..and store it in a database as well...i am using following code to define array of picturebox and load a picture in it...
Dim mimage() As PictureBox ReDim mimage(0 To num1) As PictureBox [B]mimage(num1).Picture = LoadPicture("path\filename.jpg")[/B]
but getting a error on the bold line - "object variable or with block variable not set"
Please help to resolve this...
Edited 6 Years Ago by pankaj.garg: n/a
First off, you have not instantiated a new picture box in itself, just a reference to a picturebox and to make things easier, I'll skip what that means and say this...
Put a picturebox on the form, change its index to zero (0), add a command button, add the following code...
Load Picture1(1) Picture1(1).Left = Picture1(0).Left + Picture1(0).Width + 30 Picture1(1).Top = Picture1(0).Top Picture1(1).Visible = True
Then you need to use the loadpicture function (or before visible) to put a picture in the box...
However, it looks like you are just wanting to keep an array of images in memory. If so, then you will need to change your code to this...
Dim mimage() As PictureBox ReDim mimage(0 To num1) As PictureBox mimage(num1).Picture = LoadPicture("path\filename.jpg")Dim mimage() As PictureBox ReDim Preserve mimage(0 To num1) As PictureBox Set mimage(num1).Picture = LoadPicture("path\filename.jpg")
why don't you use a imagelist control as picture container?
Imagelist control is in components.. Microsoft Windows Common controls 6.0 (SP6)
code for imagelist = (form with 3 pictureboxes and indexed from 1 to 3)
Dim i as integer ImageList1.ListImages.Add , , LoadPicture("D:\xfer\Guido_Geurs_1.jpg") ImageList1.ListImages.Add , , LoadPicture("D:\xfer\Guido_Geurs_2.jpg") ImageList1.ListImages.Add , , LoadPicture("D:\xfer\Guido_Geurs_3.jpg") For i = 1 To ImageList1.ListImages.Count Pic(i).Picture = ImageList1.ListImages(i).Picture Next
thank you vb5prgrmr,
but the problem seems to remain the same..i think i am doing something very basic wrong !!
to make things simpler for myself..i tried adding a single picturebox at runtime..with following code...
Private Sub Command1_Click() Dim mimage As PictureBox Set mimage.Picture = LoadPicture("path\image.jpg") end sub
but still the result is same..same error !!
thanks ggeu for reply,
but i want to add picturebox at runtime...and cant have them beforehand on the form...and i am finding it difficult to add picturebox at runtime !!
for adding commands in VB, place a command (picturebox) with index=0 in the form and load the same command with an increment of the index like this:(see attachment)
Private Sub Command1_Click() Load Picture1(Picture1.UBound + 1) Picture1(Picture1.UBound).Top = Picture1.UBound * 200 Picture1(Picture1.UBound).Visible = True End Sub
do you want the pictures selected from a filelist?
This is with adding from a filelist and previewing. see attachment
You have gone over the same information that I have posted and the OP, pan, has replied to my post that you repeated, that they cannot place a control on the form at design time and that they must create the control at run time. Which means this is the code pan is looking for...
Dim C As PictureBox Set C = Controls.Add("VB.PictureBox", "Picture1") C.AutoRedraw = True C.AutoSize = True C.Picture = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Bitmaps\Assorted\balloon.bmp") C.Visible = True
thanks ggeu for all the effort and help..
your solutions were useful...but i was looking for some like what vb5prgrmr gave...
sorry if i was not clear in my requirements..
thanks vb5prgrmr for the code...
this is what i was looking for...sorry if i was not very clear in my requirements earlier :)
it would be of great help if you could tell me how to use this as array now?
one more thing, i have to use 'mouse events' with the control..so as i understand, the declaration would become something like
dim WithEvents c As Picturebox
please guide me to complete this..
While this is for text boxes, it has the info you need. All you need to do is to apply it to your needs.
Very late into the thread... But why not Create a Control Array of Picture Boxes...? Place a PictureBox on the Form and Set Index =0 and Visible =False. Now when you want to load one more pict box, then use this code:
Dim t As Integer t = Pict1.UBound + 1 Load Pict1(t) Pict1(t).Visible = True Pict1(t).Left = Pict1(t - 1).Left Pict1(t).Top = Pict1(t - 1).Top + 300
Also, you can directly write the code in Mouse events for Pict1, checking the Index property...
Edited 6 Years Ago by QVeen72: n/a
Maybe this will help: see attachment
Sorry, forgot to add the code for Dir and Drive.
Thanks 'vb5prgrmr' and 'ggeu' for helping me to understand this...
Thanks QVeen72 for suggestion...but its already been suggested by 'ggeu' and 'vb5prgrmr'
Hello All ...
Iam Getting An Error With try to excecute the stored procedure .
I have Have Sql database , the stored procedure like so :
USE [MPRS] GO /****** Object: StoredProcedure [dbo].[Search_Licenses_By_Number] Script Date: 26-Nov-16 8:06:52 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE ...
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...