|
-
Apr 27th, 2000, 09:43 PM
#1
Thread Starter
Fanatic Member
Can anyone tell me how to load all the pictures (of same size) that are present in any directory on to a form?
-
Apr 27th, 2000, 11:30 PM
#2
Addicted Member
1st make a dir "*.bmp" (for instance) to the directory where the images are and until the dir statement returns "" keep loading the images. You must create an array of pictureboxes.
-
Apr 27th, 2000, 11:53 PM
#3
'******************************************
'in the module declare following
'******************************************
Option Explicit
Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * 260
cAlternate As String * 14
End Type
Declare Function FindClose Lib "kernel32.dll" (ByVal hFindFile As Long) As Long
Declare Function FindNextFile Lib "kernel32.dll" Alias "FindNextFileA" (ByVal hFindFile As _
Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" _
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
'*********************************************
'on any event that you need, this is the code
'**********************************************
Dim hsearch As Long ' handle to the file search
Dim findinfo As WIN32_FIND_DATA
Dim success As Long
Dim buffer As String
Dim retval As Long
Dim i As Integer
dim DirPath as string
' Begin a file search:
DirPath="Path to the directory that has your bmp files\"
hsearch = FindFirstFile(DirPath & "*.bmp", findinfo)
If hsearch = -1 Then
exit sub
End If
Do ' begin loop
buffer = Left(findinfo.cFileName, InStr(findinfo.cFileName, vbNullChar) - 1)
i = i + 1
Load Image1(i)
Image1(i) = LoadPicture(DirPath & buffer)
Image1(i).Top = Image1(i - 1).Top + Image1(i - 1).Width + 50
Image1(i).Visible = True
success = FindNextFile(hsearch, findinfo)
Loop Until success = 0
retval = FindClose(hsearch)
-
Apr 27th, 2000, 11:54 PM
#4
Fanatic Member
Try something like this:
Make your imagebox a control array.
Code:
'PURPOSE:List the Files in the selected directory
Dim str_data As string
dim int_Pic as integer
str_data = Dir(strDir & "*.jpg")
Do Until str_data = ""
image1(x).picture = loadpicture(str_data)
int_Pic = int_pic + 1
str_data= Dir()
Loop
Chemically Formulated As:
Dr. Nitro
-
Apr 28th, 2000, 08:33 AM
#5
Thread Starter
Fanatic Member
Thanks a lot HELENZAK and NITRO.
Kinjal
-
Apr 28th, 2000, 03:23 PM
#6
transcendental analytic
If you're going outo resources/performance/RAM by creating too many pictureboxes, just ask me and I'll help you with bitblt
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Apr 28th, 2000, 04:12 PM
#7
Thread Starter
Fanatic Member
Hello HelenZak and Nitro,
I tried both of yours code but none of them worked.
HelenZak, your code is showing error "Function not defined" for FindFirstFile.
Since I've never used this API I don't know it's syntax or what wrong. Please give the right code.
And Nitro you code is showing file not found even though the file is present in the directory.
Thanks a lot both of you.
Kinjal
-
Apr 29th, 2000, 01:45 PM
#8
Fanatic Member
Hello Kinjalgp!
I bet you did not change the directory to your search directory.
You might need to use CHDIR "C:\Your Directory".
You can use the following to tell your current directory.
msgbox CurDir()
Please keep me posted, because I am challenge to fix my mistake.
Thank You.
Chemically Formulated As:
Dr. Nitro
-
Apr 29th, 2000, 02:40 PM
#9
Thread Starter
Fanatic Member
No Nitro, I changed the directory but the program was showing the full directory path and along with the picture name and "Picture NOT FOUND".
Kinjal
-
Apr 29th, 2000, 03:09 PM
#10
Fanatic Member
What about an extra "\"?
Can you stick the entire string into a msgbox and check if it is correct. I really sounds like a path problem.
You might have to change the "DO Loop" to a "For Loop" basing on the total number of Picturebox controls you have on your form.
Chemically Formulated As:
Dr. Nitro
-
Apr 29th, 2000, 10:17 PM
#11
transcendental analytic
Load this into notepad and save it as a form. then run it and find your directory. You can modify it for your purpose 
VERSION 5.00
Begin VB.Form Form1
Caption = "Kedasus 5 minutes demo"
ClientHeight = 4425
ClientLeft = 60
ClientTop = 345
ClientWidth = 11130
LinkTopic = "Form1"
ScaleHeight = 4425
ScaleWidth = 11130
StartUpPosition = 3 'Windows Default
Begin VB.DirListBox Dirc
Height = 2790
Left = 0
TabIndex = 0
Top = 1200
Width = 1695
End
Begin VB.Image img
Height = 855
Index = 0
Left = 120
Top = 120
Width = 855
Visible = 0 'False
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Dirc_Change()
Path = Dir(Dirc.Path & String(1 + Int(Right(Dirc.Path, 1) = "\"), "\") & "*.jpg")
Do While Len(Path)
Load img(img.UBound + 1)
With img(img.UBound)
.picture = LoadPicture(Dirc.Path & String(1 + Int(Right(Dirc.Path, 1) = "\"), "\") & Path)
.Visible = True
.Stretch = True
.Move img.UBound * 500, 0, 500, 500
End With
Path = Dir()
Loop
End Sub
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Apr 30th, 2000, 08:20 PM
#12
'This Declarations are used in Option Explicit of the form
'If you need to use them in the Module You have to
'use keyword Public before Type
'and Public Before Daclare
Option Explicit
Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * 260
cAlternate As String * 14
End Type
Declare Function FindClose Lib "kernel32.dll" (ByVal hFindFile As Long) As Long
Declare Function FindNextFile Lib "kernel32.dll" Alias "FindNextFileA" (ByVal hFindFile As _
Long, lpFindFileData As WIN32_FIND_DATA) As Long
Declare Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" _
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
'*********************************************
'on any event that you need, this is the code
'Pretend that this is cmdShow_Clik()
'**********************************************
'First Declare all local variables
Dim hsearch As Long ' handle to the file search
Dim findinfo As WIN32_FIND_DATA
Dim success As Long
Dim buffer As String
Dim retval As Long
Dim i As Integer
dim DirPath as string
' Begin a file search:
'If you have your picture files in "C:\MyPictures"
'you have to use "\" that separates Directory from Files
DirPath="C:\MyPictures\"
'The Function FindFirstFile works with 2 parameters
'first is a path of the file in your case it is DirPath & "*.bmp"
'second is a user define type
hsearch = FindFirstFile(DirPath & "*.bmp", findinfo)
If hsearch = -1 Then
exit sub
End If
Do ' begin loop
buffer = Left(findinfo.cFileName, InStr(findinfo.cFileName, vbNullChar) - 1)
i = i + 1
Load Image1(i)
Image1(i) = LoadPicture(DirPath & buffer)
Image1(i).Top = Image1(i - 1).Top + Image1(i - 1).Width + 50
Image1(i).Visible = True
success = FindNextFile(hsearch, findinfo)
Loop Until success = 0
retval = FindClose(hsearch)
-
Apr 30th, 2000, 08:30 PM
#13
Lively Member
In Nitro's code, you're going to have to do a couple things different. first, you're going to have to create the array.. that isn't done here. Then you're going to have to create each new element of the array as you get another picture. Then, where the line "image1(x).picture = loadpicture(str_data)" is.. change the (x) to (int_pic). "x" isn't defined here and what's going to happen is either the compiler is going to tell you that there's no "x" or even worse, you have a global var of "x" and it's going to use that one. Here's his code again.
'PURPOSE:List the Files in the selected directory
Dim str_data As string
dim int_Pic as integer
str_data = Dir(strDir & "*.jpg")
Do Until str_data = ""
image1(x).picture = loadpicture(str_data)
int_Pic = int_pic + 1
str_data= Dir()
Loop
*** Hope that points you in the right direction.
-
Apr 30th, 2000, 11:56 PM
#14
Thread Starter
Fanatic Member
If you want I can send you my program. Give me your email address.
I tried hard to make it run but it is getting the bitmaps name and giving error "X.bmp" not found. I don't know why it it saying so. If the program can find the file name why can't it load it? 
Kinjal
-
May 1st, 2000, 12:18 AM
#15
transcendental analytic
You didn't try my sample?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 1st, 2000, 01:00 AM
#16
Thread Starter
Fanatic Member
yes I tried your sample just now. Now I got what I wanted but what if my directory path is constant? Like (App.path & "\Bitmaps" & "\" & "*.bmp")?
I tried to change the path in your code to a fixed under a command button but VB shows "Object required" and points at the path? 
Kinjal
-
May 1st, 2000, 01:25 AM
#17
Thread Starter
Fanatic Member
I tried your sample and is just what I wanted. But what if my directory path is constant like (App.Path & "\Bitmap" & "\" & "*.BMP"). I tried to make these changes in your code under command button but didn't work.
-
May 1st, 2000, 03:30 AM
#18
transcendental analytic
Well remove the filelistbox and replace those two:
Code:
Dirc.Path & String(1 + Int(Right(Dirc.Path, 1) = "\"), "\")
with your own path and it should end with "\"
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 1st, 2000, 02:18 PM
#19
Thread Starter
Fanatic Member
What did you meant by replace those two ?
I am not getting anything on my form and no errors when I replaced Direc.path to App.Path & "\Bitmap" & "\"* "*.bmp") ?????
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|