Solved

What is wrong with my VB6? For each string in array

Posted on 2014-12-04
4
144 Views
Last Modified: 2014-12-18
I am coding up someting that shoudl be simple. I am sure my code has an issue.

My code is below. THe issue I am having is that during the For i=0 there is an issue when inserting into the database it does not insert anything it just leaves it blank. My databasde value should be a string.

My goal is to have it run a query for each string that is in the array and use that string that it is currently on in the query.

Public pdffile As ADODB.Stream
Sub main()


    Const delimiter As String = ","

    Dim i As Integer
    Dim iterStr As String
    Dim mainlist As String
    Dim sublist As String
    Dim split_sublist() As String
    Dim pdfpath, pdfpath1 As String
    Dim sql As String
    Dim database As New ADODB.Connection
    Dim rs As ADODB.Recordset


    mainlist = AccountVariable("xrefidlist")
    sublist = AccountVariable("xrefidlist")

    split_sublist = Split(sublist, delimiter)

    For i = 0 To UBound(split_sublist)
        database.ConnectionString = "Provider=sqloledb; Data Source=192.168.2.121\EMMSDE;Initial Catalog=outlookreport; User Id=xxxxx; Password=xxxxx;"
        database.Open
        sql = "SELECT * FROM comlog"
        Set rs = New ADODB.Recordset

        rs.Open " select * from comlog", database, adOpenKeyset, adLockOptimistic
        rs.AddNew

        Set pdffile = New ADODB.Stream
        pdffile.Type = adTypeBinary
        pdffile.Open
        pdffile.LoadFromFile "C:\test.pdf"
        rs.Fields("location") = pdffile.Read
        rs.Fields("xrefid") = split_sublist(i)
        rs.Fields("sender") = "Testing VB6"
        rs.Fields("status") = "Unread"
        rs.Fields("fromemail") = "gashlin@gmail.com"
        pdffile.Close
        Set pdffile = Nothing
        rs.Update
        Set rs = Nothing

        database.Close

    Next i

    'clean mainlist the way you want.
    mainlist = Trim(mainlist)

totaloutput = Left(mainlist, Len(mainlist) -1)
AccountVariable("recievers") = totaloutput

End Sub

Open in new window

0
Comment
Question by:desiredforsome
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40481626
Move your database connection/open/close outside the loop - silly to keep opening and closing it on every iteration of the loop
Remove the SELECT - you are adding fields so no point doing a select.

Is it actually looping properly?
Have you checked split_sublist is what it should be?
Any error messages?
0
 

Author Comment

by:desiredforsome
ID: 40481729
actually it turns out my system froze up and that was the issue. HOwever, How would I go about moving my db connection outside the loop so that it can insert it freely. Would I do something like

DB.open...

Loop

After Loop

Db.close?
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40481739
    database.ConnectionString = "Provider=sqloledb; Data Source=192.168.2.121\EMMSDE;Initial Catalog=outlookreport; User Id=xxxxx; Password=xxxxx;"
    database.Open

    For i = 0 To UBound(split_sublist)

        Set rs = New ADODB.Recordset
        rs.AddNew

        Set pdffile = New ADODB.Stream
        pdffile.Type = adTypeBinary
        pdffile.Open
        pdffile.LoadFromFile "C:\test.pdf"
        rs.Fields("location") = pdffile.Read
        rs.Fields("xrefid") = split_sublist(i)
        rs.Fields("sender") = "Testing VB6"
        rs.Fields("status") = "Unread"
        rs.Fields("fromemail") = "gashlin@gmail.com"
        pdffile.Close
        Set pdffile = Nothing
        rs.Update

    Next i
    Set rs = Nothing
    database.Close

Open in new window

0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question