Author Topic: i have difficulties in understanding  (Read 3532 times)

obductor

  • Newbie
  • *
  • Posts: 30
i have difficulties in understanding
« on: February 16, 2008, 07:27:18 PM »
Hi All.

i saw an data base exemple that gambas have, but unfortunately i cant understand  how can i add a photo and his name on data base, in fact i really wanted a texbox, where i write the name of the picture, and than a picture box where i make the photo upload together with the name. sameone have suggestion in  a simple form?

Thanks
Se eu não sou o que penso ser, nem também sou o que pensam que sou.

Linux Basic

i have difficulties in understanding
« on: February 16, 2008, 07:27:18 PM »

quince

  • Jr. Member
  • **
  • Posts: 69
Re: i have difficulties in understanding
« Reply #1 on: February 17, 2008, 06:52:32 AM »
hi,

if you're using a mysql database then i think it's not possible to store picture in
but you can always store a path to picture,

so, i would make a form with textbox for then name of picture and picture box, two buttons and one dialog-file chooser
when you click the first button-OpenButton, dialog-file chooser opens, then you chose a picture, here you'll need  to
catch location of the picture, and close dialog
chosen picture loads in a picture box, in the textbox enter a name of picture,
clicking on the second button-SubmitButton- should store name and location in database,

you can always show picture using picturebox and a path to the picture that is stored in database

i hope you understand me, my english is not quite good,
and take this with reserve, this is nothing more than just an idea
« Last Edit: February 17, 2008, 06:59:31 AM by quince »

timothy

  • Sr. Member
  • ****
  • Posts: 319
Re: i have difficulties in understanding
« Reply #2 on: February 18, 2008, 03:20:21 AM »

You can store Pictures in a database in Gambas 2. Have a look at the PictureDatabase example in Gambas 2. This is for SQLite. But the notes in the code show how to swap it to MySQL and PostgreSQL.

Also have a look at the topic http://forum.stormweb.no/index.php/topic,305.0.html
42 - So long and thanks for all the fish.

obductor

  • Newbie
  • *
  • Posts: 30
Re: i have difficulties in understanding
« Reply #3 on: February 20, 2008, 07:55:39 PM »
Hi.

I have use the example gambas2. And  i add 2 news line

1º (ModuleDatabase)
Code: [Select]
    pictureTable = databaseConnection.Tables.Add("pictures")
    pictureTable.Fields.Add("id", db.Serial) '             id          field as autoinc integer
    pictureTable.Fields.Add("thumb", db.Blob) '            thumb       field as blob
    pictureTable.Fields.Add("image", db.Blob) '          ' image       field as blob
    pictureTable.Fields.Add("description", db.String, 0) ' description field as unlimited string
    pictureTable.Fields.Add("name", db.String, 0) ' name
    pictureTable.Fields.Add("ab", db.String, 0) ' about photo
    pictureTable.PrimaryKey = ["id"]
    pictureTable.Update()


I created two Text's Box with TextBoxName.Text's name and TextBoxAB.Text and before I want to upload, i want insert these two textbox's.(FormPictureDatabase)

Code: [Select]
PUBLIC SUB Dados()

TextBoxName.Text = "roberto"
TextBoxAB.Text = "Good Dogs"

END

And my PUBLIC SUB Form_Open() i write Dados()

After my ModuleDatabase i change the code

Code: [Select]
' Add description and update
newPicture["description"] = "Image " & File.BaseName(ImagePath) & "  added: " & Format(Now, "dddd, dd mmmm yyyy hh:nn:ss")
newPicture["name"] = FormPictureDatabase.Dados
newPicture["ab"] = FormPictureDatabase.Dados

But when i run gambas, he say this:

Add database record error
------------------------
Error:
Type mismatch: wanted Variant, got Funciton instead.
-----------------------

(thank u quince  and timothy)

Se eu não sou o que penso ser, nem também sou o que pensam que sou.

timothy

  • Sr. Member
  • ****
  • Posts: 319
Re: i have difficulties in understanding
« Reply #4 on: February 21, 2008, 06:10:16 AM »

Dados() is a SUB and does not return a value. This results in your error. ??? Maybe the error message is a bit misleading.

Try using a FUNCTION and returning a value. Something like this:

Code: [Select]

PUBLIC FUNCTION Dados() AS String
 TextBoxName.Text = "roberto"
 TextBoxAB.Text = "Good Dogs"
  RETURN TextBoxName.Text & " " & TextBoxAB.Text
END


This would work. But you possibly want some other version to get the values you want.  :)
« Last Edit: February 22, 2008, 03:04:02 AM by timothy »
42 - So long and thanks for all the fish.

obductor

  • Newbie
  • *
  • Posts: 30
Re: i have difficulties in understanding
« Reply #5 on: February 21, 2008, 07:36:55 PM »
Appears the same mistake.
And gambas2 not accepting the  RETURN TextBoxName.Text & "" & TextBoxAB.Text

Thanks.
Se eu não sou o que penso ser, nem também sou o que pensam que sou.

timothy

  • Sr. Member
  • ****
  • Posts: 319
Re: i have difficulties in understanding
« Reply #6 on: February 22, 2008, 03:03:20 AM »

 8) Sorry my fault. Missed AS String out of the line that declares the function

Code: [Select]

PUBLIC FUNCTION Dados() AS String
 TextBoxName.Text = "roberto"
 TextBoxAB.Text = "Good Dogs"
  RETURN TextBoxName.Text & " " & TextBoxAB.Text
END


(PS: I have edited the above example to hide my error.)
42 - So long and thanks for all the fish.

obductor

  • Newbie
  • *
  • Posts: 30
Re: i have difficulties in understanding
« Reply #7 on: February 22, 2008, 04:08:31 PM »
Done. Thank u timothy
Se eu não sou o que penso ser, nem também sou o que pensam que sou.

obductor

  • Newbie
  • *
  • Posts: 30
Re: i have difficulties in understanding
« Reply #8 on: February 25, 2008, 05:25:02 PM »
timothy
how can i make tone image update? or how can i edit a photo? by a button
Se eu não sou o que penso ser, nem também sou o que pensam que sou.

timothy

  • Sr. Member
  • ****
  • Posts: 319
Re: i have difficulties in understanding
« Reply #9 on: February 26, 2008, 02:42:59 AM »

You can use the Draw methods to draw on a Picture. Look in the Gambas help for the Draw object.

This example assumes you have a Button and a PictureBox on a form. When you click on the button you are asked to open an image file. A timestamp of when the file was opened is drawn on the bottom right of the image and then displayed in a PictureBox.

The code is for Gambas 2.

Code: [Select]

PUBLIC SUB ButtonOpen_Click()
  DIM p AS Picture
  Dialog.Filter = ["*.png *.jpg *.jpeg", "Image Files"]
  Dialog.Title = "Open an Image file"
  IF Dialog.OpenFile() THEN RETURN
  p = Picture.Load(Dialog.Path)
  PictureBoxImage.Picture = Timestamp(p, Now)
  PictureBoxImage.Height = p.Height
  PictureBoxImage.Width = p.Width
CATCH
  Message.Warning("<b>Could not open image file</b><hr>Error: " & Error.Text)
END

PRIVATE FUNCTION Timestamp(VideoPicture AS Picture, ImageTime AS Date) AS Picture
  DIM formatTime AS String
  DIM dateTop AS Integer
  DIM dateLeft AS Integer
  DIM dateWidth AS Integer
  DIM dateHeight AS Integer
  formatTime = Format(ImageTime, "dddd, dd mmmm yyyy hh:nn:ss")
  Draw.Begin(VideoPicture)
  ' Set font properties
  Draw.Font.Bold = TRUE
  ' Get dimensions to place date in bottom left corner of the picture
  dateHeight = Draw.TextHeight(formatTime)
  dateTop = VideoPicture.Height - dateHeight
  dateWidth = Draw.TextWidth(formatTime)
  dateLeft = VideoPicture.Width - dateWidth
   ' Draw a background rectangle
  Draw.FillColor = Color.DarkBlue
  Draw.FillStyle = Fill.Solid
  Draw.Rect(dateLeft, dateTop, dateWidth, dateHeight)
  ' Draw text
  Draw.ForeColor = Color.White
  Draw.Text(formatTime, dateLeft, dateTop)
  Draw.End()
  RETURN VideoPicture
END

42 - So long and thanks for all the fish.

obductor

  • Newbie
  • *
  • Posts: 30
Re: i have difficulties in understanding
« Reply #10 on: February 27, 2008, 01:38:15 PM »
Sorry timothy, but i need save the edit photo in the Database.
Se eu não sou o que penso ser, nem também sou o que pensam que sou.

dim

  • Newbie
  • *
  • Posts: 12
Re: i have difficulties in understanding
« Reply #11 on: March 11, 2008, 02:49:56 PM »
i also have some difficulties in understanding for some things.

For example what is toolbox property of a form? When i set it to TRUE the window disapears.


johnaaronrose

  • Newbie
  • *
  • Posts: 5
Re: i have difficulties in understanding
« Reply #12 on: January 09, 2012, 11:20:21 AM »
I saw your message below.It referred to the PictureDatabase example in Gambas 2. Could you point me to it's URL?


You can store Pictures in a database in Gambas 2. Have a look at the PictureDatabase example in Gambas 2. This is for SQLite. But the notes in the code show how to swap it to MySQL and PostgreSQL.

Also have a look at the topic http://forum.stormweb.no/index.php/topic,305.0.html
Regards,
John

johnaaronrose

  • Newbie
  • *
  • Posts: 5
Re: i have difficulties in understanding
« Reply #13 on: January 10, 2012, 04:25:38 AM »
I'm using Gambas2. When I started it I noticed the 'Open Example' menu entry which had the 'Picture Database' example in it. I'd forgotten about this in Gambas. I've been too involved with Android of late!
Regards,
John