469,126 Members | 1,256 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,126 developers. It's quick & easy.

Reg: Where is My Output? after Pressing the run button

Hi everyone...

I am using Visual basic 6.0 version...as I said in the previous thread I am very much new to Visual basic and poor knowledge in programming...I have done a small program in it to extract a particular data from the database of Mysql...In the program I have taken a OK button and in that I have written some lines of code to extract the data...I thought if I press OK button in the output I will get the list of the extracted data...but there is nothing displaying even after pressing the Ok button the screen stay's still...can you help me in this..This is the program
Is it necessary to give some plug-ins if I am using database in Visual basic..if so how to give that?
Option Explicit
'>>>>>>>>>>>>>>>>>>>>>>>

Const BUTTON1 = "&OK"

'>>>>>>>>>>>>>>>>>>>>>>>

Private Sub Okbutton_Click()

Dim sConnect As String
Dim db As Database
Dim rs As Recordset
Dim doubleID As Double
Dim doubleID1 As Double
Dim intstring As String

sConnect = "ODBC;DSN=WinUTMS_RT_DB;UID=Localhost;PWD=;Databas e=WinUTMS_RT_DB;"

Set db = gwsMainWS.OpenDatabase("", 0, 0, sConnect)

Set rs = db.OpenRecordset("SELECT Messwert, UPLimWert FROM abssubtest where Messwert LIKE ")
Do While Not rs.EOF
doubleID = rs!Messwert
doubleID1 = rs!UPLimWert
intstring = rs.Fields(1)
rs.MoveNext
Loop
End Sub
Fast reply will be really helpfull for me

Thanks and regards
Siva
Mar 25 '09 #1
23 1641
vdraceil
236 100+
What you have done is just open a database,read it and store it in a variable(actually you are overwriting the variable in your do while loop)..you must have to use some sort of output actions/commands like msgbox or you can write your output in a text file etc..
try writing..
msgbox "doubleID: " & doubleID & vbnewline & "doubleID1: " & doubleID1 & vbnewline & "intstring: " & intstring
inside your do while loop.
Mar 25 '09 #2
debasisdas
8,127 Expert 4TB
you have done nothing to get any output on the screen in your code.
Mar 26 '09 #3
I am getting a compile error

"User-defined type not defined"
and after pressing Ok, the cursor is going to "Dim db As Database" in the program....

it may be because of the library files...can you tell me how to add the library files for the database....if not what might be the reason
Mar 27 '09 #4
EYE4U
75
Add Reference to Microsoft ADO Data 2.0.

ARUZ
Mar 29 '09 #5
Sorry I didn't get you...´can you explain in detail
Mar 30 '09 #6
EYE4U
75
Goto Project menu and select References. A Dialogue Box will appeared from that box you have to check Microsoft ADO Data 2.0 and then press OK.

ARUZ
Mar 30 '09 #7
Thank you...now the program is running!!!....

Can you help me how to Take a FILE in between the program to save the extracted data into it so as it could be helpfull for the future, analysis task.


Thank you

Regards
Siva
Mar 30 '09 #8
EYE4U
75
Sorry i didnt get you. DO you want to save data to a file from some database???
Mar 30 '09 #9
Private Sub Okbutton_Click()
On Error Resume Next

Dim sConnect As String
Dim db As Database
Dim rs As Recordset
Dim Ws As Workspace
'Dim ID As Double
'Dim doubleID1 As Double
Dim intstring As String

Set Ws = DBEngine.Workspaces(0)

sConnect = "ODBC;DSN=WinUTMS_RT_DB;UID=Localhost;PWD=;Databas e=WinUTMS_RT_DB;"

Set db = Ws.OpenDatabase("", 0, 0, sConnect)

Set rs = db.OpenRecordset("SELECT Modus FROM absprfg")
Do While Not rs.EOF
'ID = rs!Messwert
'doubleID1 = rs!UPLimWert
intstring = rs.Fields("Modus")
rs.MoveNext
Loop
End Sub
ya..If I run the above program, there are no errors in it and I am able to extract the data from the database...now I have to save that extracted data in an excel sheet directly with the help of program... i.e. I have to take a file and write some program so that if I run the program the extracted data will be automatically saved to an excel sheet...hope you understand!...please can you help me in this...

Thank you for your support!
Mar 31 '09 #10
EYE4U
75
Ok i ll upload an example in which you can convert a mdb file into excel work sheet...
Mar 31 '09 #11
Ok...I'll wait for you...if possible make it fast ah.....thanq
Apr 1 '09 #12
EYE4U
75
I m sorry for replying late....

The attached application can convert mdb file into different formats....

Regards
ARUZ
Attached Files
File Type: zip mdb converter.zip (16.8 KB, 62 views)
Apr 3 '09 #13
thank you for the reply...may be you might have understand my question in wrong way or my english was poor..I dono...but I am not looking for the data conversion...already I have the data that is in the required format...which I dont need to convert...all I need is the extracted data should be saved to file that was specified by me...I have tried some thing if you look at the program....now I can take my extracted data to that particular file...but the problem is if the data is one line it is perfect and if I have lots of data there comes the problem....all data is storing in one row....but I want the data in different rows..I have used "\n" but getting some errors
Do While Not rs.EOF
'ID = rs!Messwert
'doubleID1 = rs!UPLimWert
intstring = rs.Fields(0)
rs.MoveNext

Open "K:\user\Dhanekula\Visual Baisc\file.csv" For Random As #FreeFile
intMsg = MsgBox("File file.csv opened")
Print #1, intstring
intMsg = MsgBox("Writing a" & intstring & " to file.csv ")

Close #1
'intMsg = MsgBox("File file.csv closed")
Loop
If you look at the program...an excel sheet will be automatically added in the given path after I run the program..and the data will be printed to that with the print command...till that is Ok but later I have some problem's....

1. How to get the data in different rows if I have more than one testname(fields)
2. How to convert ',' to '.' (i.e. If I have a number 3,46 I need to convert it ti 3.46)

Please can you help me in this situation....
thank you for the example program given in the previous thread...it might help me for the other project
Apr 3 '09 #14
EYE4U
75
Use this code to replace , with .
Expand|Select|Wrap|Line Numbers
  1. msgbox Replce ("3,46",",",".")
Suppose you have following Fields in database table :
1. ID
2. Name
3. Address

Expand|Select|Wrap|Line Numbers
  1. msgbox (rs.Fields(0) & rs.Fields(1) & rs.Fields(2)
This code will get the id, name and address and show them in a message box.

If you need any example just ask for that.

Regards
ARUZ
Apr 3 '09 #15
Is Append in the open statement correct, if I use this I am only getting the last field data if I have n fields...and If I use Output instead of Append I am getting only the last value of last field...and one more thing if I use the msgbox I was asking to press Ok for every data that is entering to the file...I have 100's of data and I can't press Ok for each time...any solution for that

the other question was?

If I write some SQL statement to extract particular number of rows from a table. I need the output with heading of particular row and the data regarding that...

i.e. suppose if have a table name of Year and with rows from January to febrauary with each month consisting of 100 data "may be string or Integer"

If My Sql statement SELECT January , March, may FROM Year with January like "Sunday"...then I need the output like

January March May in different rows with the data under each row from the original table "Year" that has only Sunday in January....it may be more than 40 values and now if the other rows which are March and May have some integer value in it with "," I need the conversion here to convert each and every value of that particular row into "."

If you have some example program of such kind...it would be really helpfull for me
Apr 3 '09 #16
EYE4U
75
You need a loop to traverse your recordset for example :
Expand|Select|Wrap|Line Numbers
  1. Dim s as String
  2.  
  3. While rs.EOF = True
  4. For i = 0 To 4
  5. s = s & rs.Fields(i)
  6. Next
  7. WriteToFile(s)
  8. rs.MoveNext
  9. Wend
  10.  
WriteToFile is writing data to file.
This code will traverse all database and will copy the data to the file.

I m again confused with your question.
You have executed the query and you have got January, March and May Columns from database.

Now in which rows you want to show your data...
Are you using some kind of grid control, list control or what??

Regards
ARUZ
Apr 3 '09 #17
Hey...I'm sorry...bit confused with rows and columns...but anyways u got me correct...and regarding the program I am getting an error "Sub or Function not defined". and highlighting at WritetoFile
Apr 3 '09 #18
EYE4U
75
Function Writetofile, you have to make this function i mean this function will save the data to file....

If you still didnt understand ask...

Regards
ARUZ
Apr 4 '09 #19
Sorry I didn't get you!..
Apr 6 '09 #20
EYE4U
75
Replace this with your filing code...
The code which is saving the data to file...
Apr 6 '09 #21
can I write this.writetofile(s)...instead of writetofile(s)...is that what you mean...if so I didn't get the output..the screen was blank!
Apr 6 '09 #22
EYE4U
75
wait wait wait....
right now i m in my university i ll upload an example for this problem when i ll get back to home....

OK
Apr 6 '09 #23
Ok...Just for you to remember...I am searching for the code that the extracted data with the help of SQL statement should be saved in file".csv"...and before doing that if the data has "," in it then it should be converted to "." automaticallay and should save in the file...

Thank you very much for your help
Apr 6 '09 #24

Post your reply

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

Similar topics

2 posts views Thread by Cindy | last post: by
1 post views Thread by Anurag | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.