borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (I could not delete the file)Next Topic (Open/Clode DB Using ADO in VB6) New Topic New Poll Post Reply
AndreaVB Forum : Database : Help with Image links in Db, please
Poster Message
wiseguy2004
Level: Trainee

Registered: 01-10-2007
Posts: 1

icon Help with Image links in Db, please

I sure hope there's someone here that can help me with this - I am JUST starting out with VB6, not used to OOP at all, but I believe this is a simple problem that someone here could help me solve...

I'm trying to create a database in VB6 (or VB 2005 Express Edition) to catalog custom content for the game The Sims 2 (Clothing, Furniture, Hacks/Mods, etc.). I plan to use either an Access97 table or SQL Server 2005 as the Db (unless I can find an alternative that is as easy to manipulate). I wouldn't mind if it used a plain-text file to store the data, but I suppose a 'real' database would be better.

I want to store the Path/Filename of 1 or more screenshots in fields of the Db (text fields), NOT store the actual picture itself, as that would bloat the Db terribly (most players have hundreds, and sometimes up to tens of thousands of items of custom content.)

I have the table created with all my fields in it - it's structured like this:


Field        Type        Length
-----        ----        ------

ItemID       Number     (Long Integer)
Name         Text       (255)
Filename     Text       (255)
Creator      Text       (255)
Link         Hyperlink  
AddDate      Date/Time
TS2          Yes/No
UNI          Yes/No
NL           Yes/No
HPP          Yes/No
OFB          Yes/No
FFS          Yes/No
GLS          Yes/No
PET          Yes/No
HHS          Yes/No
SSN          Yes/No
CEL          Yes/No
H&M          Yes/No
Description  Memo
Pic1         Text       (255)
Pic2         Text       (255)

I have my VB form all laid out with connections from the various Text Boxes, Command Buttons, Image Boxes, etc. to their respective fields.

and all seems to work fine, until I get to the part where I put the screenshot(s) in...

Here's the code that I'm using:


Private Sub cmdAddPic1_Click()
Dim Pic1Location As String
cd1.ShowOpen
Pic1Location = cd1.FileName
If cd1.FileName = "" Then GoTo subend ' In case the User clicks Cancel
txtPic1 = Pic1Location
imgPic1 = LoadPicture(txtPic1)
subend:
End Sub


This is what happens: The user clicks on the "Add Picture 1" button, commdlg32 (cd1) is invoked to browse for the desired picture. The path/filename of the chosen picture is stored as Pic1Location, and copied (as a string) to the Text Box txtPic1 (originally I just used this as a test to be sure the entire path and filename were being recognized, but then I got the idea to actually USE this as a means of saving the location into the Db). Then the image is displayed in the Image Box imgPic1 using the LoadPicture method and getting the path/filename from the Text Box txtPic1

That part seems to work - sometimes... - I can browse for the picture, locate it, the path/filename is stored, the image shows up right then in the Image Box, and the test string is saved in the field of the Db. But then part of the time I get an "Invalid Field Datatype" error when I click the "Add Item" button, or the same error when the Db is refreshed.


Private Sub cmdAdd_Click()
db1.Recordset.AddNew
End Sub


And, when the record is browsed to again, either no picture at all, or the picture from the previous record is shown in the Image Box.

I've tried it with and without using the "Add Item" button

Also, with and without using the "Update Db" button


Private Sub cmdUpdate_Click()
db1.Refresh
End Sub


But it seems to make no difference whatsoever.

I'm just totally stumped, and I can't find any info anywhere.

I will be using the LoadPicture method, but I really have to have the ability to allow the user to browse and choose a picture from anywhere on their hard drive, and have the path/filename of the picture be stored into the field.

If this were just a program for my own use I'd either store the pictures IN the Db, or maybe find a way to just manually enter the path/filename each time, but I want to release this to the TS2 community, and I HAVE to make it so each user can browse their own computer for the pictures. Eventually, I hope to also find a way to enable them to save a picture they've copied to the clipboard from a webpage, and save them the extra step of having to save it manually, but that's a "whole 'nother story" heheh.

Really, that's all the code I have - For clarity, here's the entire listing as its shown to me:


Private Sub cmdAdd_Click()
db1.Recordset.AddNew
End Sub

Private Sub cmdAddPic1_Click()
Dim Pic1Location As String
cd1.ShowOpen
Pic1Location = cd1.FileName
If cd1.FileName = "" Then GoTo subend
txtPic1.Text = Pic1Location
imgPic1 = LoadPicture(txtPic1.Text)
subend:
End Sub

Private Sub cmdAddPic2_Click()
Dim Pic2Location As String
cd1.ShowOpen
Pic2Location = cd1.FileName
If cd1.FileName = "" Then GoTo subend
txtPic2.Text = Pic2Location
imgPic2 = LoadPicture(txtPic2.Text)
subend:
End Sub

Private Sub cmdDelete_Click()
db1.Recordset.Delete
db1.Refresh
End Sub

Private Sub cmdUpdate_Click()
db1.Refresh
End Sub


I hate to ask in this way, but I really, really need a code example - I believe I understand the concept of how it's to be done, but I just can't figure out how to code it.

I've downloaded Visual Basic 2005 Express Edition as well as SQL server 2005 Express Edition from the Microsoft site, and have explored them, but it doesn't seem to be any simpler...

Google heaves a heavy sigh whenever it sees me coming, as I've searched SO many times, trying to find a solution for this...

Please help, someone.

This is to be a free application for other players of The Sims 2, so if anyone would like to help me complete it, I'd be more than happy to include your name in the credits for the program!

01-10-2007 at 05:18 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : Help with Image links in Db, please
Previous Topic (I could not delete the file)Next Topic (Open/Clode DB Using ADO in VB6) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder