?
Solved

VB and crystal reports

Posted on 2005-04-15
7
Medium Priority
?
317 Views
Last Modified: 2012-06-21
Hi,

I'm very very new to VB and need someone to please explain this code.
Thanks


'Const Record_number = 5000+
Public cn As Connection
Public mySystem
Public ConnectString, login, myDataBase
Public cntString, fName, secFname, seqFname, myBuf, logfname, reccnt
Public printername


'Public Function GetConfigSys(inParm)
'    On Error GoTo getErr
'    fni = "c:\services\general.cnf"
'    Open fni For Input As #1
'    Line Input #1, buf
'    While (Not EOF(1)) And (Left(buf, Len(inParm)) <> inParm)
'        Line Input #1, buf
'    Wend
'    If EOF(1) Then
'        GetConfigSys = "-1"
'        Else
'        GetConfigSys = Mid(buf, Len(inParm) + 1, 999)
'    End If
'    Close #1
'    Exit Function
'getErr:
'        GetConfigSys = "-1"
'End Function
Private Sub Main()
   
    myBuf = LoadFile(Command())
    constr = GetPartFromReq(myBuf, "constring" & vbTab, vbCrLf)
    seqFname = GetPartFromReq(myBuf, "lastseqfn" & vbTab, vbCrLf)
    logfname = GetPartFromReq(myBuf, "logfile" & vbTab, vbCrLf)
    stRep = GetPartFromReq(myBuf, "repname" & vbTab, vbCrLf)
    Dest = GetPartFromReq(myBuf, "Printer" & vbTab, vbCrLf)
    printername = GetPartFromReq(myBuf, "Printername" & vbTab, vbCrLf)
   
    Open logfname For Append As #2
    Print #2, Format(Now(), "dd/mm/yyyy hh:mm:ss") + UCase(stRep) + " report : Started "
    Print #2, "Destination " + Dest
    On Error GoTo errLogin
    cntr = cntr + 1
    Set cn = New Connection
    cn.CursorLocation = adUseClient
    'ConnectString = LoadFile("c:\services\SARIE\" & "repuser.sec")
    ConnectString = GetPartFromReq(myBuf, "constring" & vbTab, vbCrLf)
    'Record_number = LoadFile("c:\services\SARIE\" & "LastSeq.Seq")
    Record_number = LoadFile(seqFname)
    cn.Open ConnectString
    login = True
   
    Dim rr As Recordset
    Set rr = New Recordset
    tsql = "select business_date ,path_03 ,path_04  from config where company_code = '0000000000' "
    rr.Open tsql, cn, adOpenForwardOnly, adLockReadOnly
    repSave = rr.Fields(1).Value
    repPath = rr.Fields(2).Value
    sDATE = rr.Fields(0).Value
    'commented and changed by shaik ismail to change the date format to yyyymmdd
    'sDate = Right(sDate, 2) & Mid(sDate, 5, 2) & Left(sDate, 4)
    If UCase(stRep) = "TRANSARI" Then
       sDATE = Right(sDATE, 2) & Mid(sDATE, 5, 2) & Left(sDATE, 4)
    End If
       
    rr.Close
    'stRep = "TRANSARI"
'-----------------------------------
    scr = LoadFile(repPath & stRep & ".QUR")
    scs = LoadFile(repPath & stRep & ".QUS")
    scr = Replace(scr, "[Date]", sDATE)
    scr = Replace(scr, "[Record_Number]", Record_number)
    scs = Replace(scs, "[Date]", sDATE)
    scs = Replace(scs, "[Record_Number]", Record_number)
    'rr.Open Replace(scr, "SELECT", "SELECT RECORD_NUMBER , "), cn, adOpenForwardOnly, adLockReadOnly
    rr.Open scs, cn, adOpenForwardOnly, adLockReadOnly
   
    If rr.RecordCount <= 0 Then
        rr.Close
        Print #2, stRep + " No Entry / No Report"
        Print #2, Format(Now(), "dd/mm/yyyy hh:mm:ss") + UCase(stRep); " report : Ended successfully."
        Print #2, "################################################"
        Close #2
        MsgBox "No Entry / No Report "
        Exit Sub
    End If
    rr.MoveLast
    last_rec = rr.Fields(0).Value
   
    Open seqFname For Output As #1
    Print #1, Format(last_rec, "000000")
    Close #1
   
    Print #2, "Records to be printed : " + Str(rr.RecordCount)
    Print #2, "Last printed sequence : " + Str(last_rec)
       
    rr.Close
'---------------------------------------
    'Dest = LoadFile("c:\services\SARIE\DEST.cnf")
    GenReport repPath & stRep, Dest, scr, repSave & stRep
    If Not IsNull(Trim(printername)) And printername <> "-1" Then
       Print #2, "Printer name : " + printername
    Else
       Print #2, "Printer name : Default printer"
    End If
       
    Print #2, Format(Now(), "dd/mm/yyyy hh:mm:ss") + UCase(stRep); " report : Ended successfully."
    Print #2, "################################################"
    Close #2
    MsgBox "Report Has been generated "
    Unload frmSARI
    Exit Sub
errLogin:
    Print #2, stRep + " report cannot be generated due to the below reason"
    Print #2, "Error" + Err.Description
    Print #2, " Contact the administrator ... "
    Print #2, Format(Now(), "dd/mm/yyyy hh:mm:ss") + UCase(stRep); " report : Ended with errors."
    Print #2, "################################################"
    Close #2
    MsgBox " Contact the administrator ... "
End Sub


Public Sub GenReport(inRep, inDest, inFormula, sSave)  '

On Error GoTo genErr
    'repdir = "d:\b2b\rpt\def\"
    'repDown = "d:\b2b\rpt\Reports" & inRep
    dst = crptToWindow
    Select Case inDest
        Case "File"
            dst = crptToFile
            frmMain.repGen.PrintFileType = crptRTF
            frmMain.repGen.PrintFileName = sSave & ".rtf"
        Case "Printer"
            dst = crptToPrinter
        Case "Window"
            dst = crptToWindow
    End Select

frmSARI.repGen.Connect = ConnectString
frmSARI.repGen.ReportFileName = inRep & ".rpt"
frmSARI.repGen.SQLQuery = inFormula
frmSARI.repGen.Destination = dst

If Not IsNull(Trim(printername)) And printername <> "-1" Then
   frmSARI.repGen.printername = printername
End If
frmSARI.repGen.Action = 1

Exit Sub
genErr:
MsgBox "[" & Err.Number & "]" & Err.Description
End Sub

Public Function LoadFile(FilePath)
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Set objFileSys = CreateObject("Scripting.FileSystemObject")
    Set fs = objFileSys.GetFile(FilePath)
    Set filestream = objFileSys.OpenTextFile(FilePath, ForReading)
    LoadFile = filestream.read(fs.Size)
    filestream.Close
    Set filestream = Nothing
    Set fs = Nothing
    Set objFileSys = Nothing
End Function

Function GetPartFromReq(sDocument, sToken, eToken)
        Dim pos1, pos2
        Dim result
        result = ""
         
         
        pos1 = InStr(sDocument, sToken)
        pos2 = InStr(pos1 + 1, sDocument, eToken)
       
        If pos1 = 0 Or pos2 = 0 Then
            GetPartFromReq = -1
            Exit Function
        End If
        If pos1 > 0 Then
            If Len(eToken) <> 0 Then
                result = Mid(sDocument, pos1 + Len(sToken), pos2 - (pos1 + Len(sToken)))
            Else
                result = Mid(sDocument, pos1 + Len(sToken))
            End If
        End If
      GetPartFromReq = result
End Function

0
Comment
Question by:Samooramad
  • 3
  • 3
7 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 13793434
Is there a problem with the code or do you just need an explanation.

There is a fair amount of code doing several things.  Is there a particular area or just the code ingeneral.

mlmcc
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13793477
I think it would be better if you split this in to say 4 or 5 questions and award each question with say 100 points that way it will be easier because you can split it by each function and such like :) then that way you get all of the code explained for more or less the same amount of points and experts would be more willing to do it that way, unless there is someone going through all of it now commenting it
0
 

Author Comment

by:Samooramad
ID: 13800660
just need a main Idea..I know what its doing but just not in detail...so say a few comments on each part..then if I need more details I will ask new questions..ok?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Samooramad
ID: 13800662
mlmcc,
no tere is no problem with the code
0
 

Author Comment

by:Samooramad
ID: 13800667
I mean could someone just say which function is doing what...
please :)
0
 
LVL 23

Accepted Solution

by:
gecko_au2003 earned 2000 total points
ID: 13800710
If you could copy and paste the main parts of the code that you dont understand or that you would like explaining that might help a lot !!

From what I can tell it connects to the database, logs into it, then it runs some querrys to return information that it wants to be saved, saves it , then it creates the reports based on those querries. And prompts you with a message box once it has created the reports :) Anyway , once we know the mains parts of the coding that you need explained or commented then that may make things eaiser :)
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13804758
Thanks for the grade and points !! I wasnt expecting that lol. If you would like to post parts you dont understand of the code then go from there ?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

829 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