Solved

for each loop

Posted on 2014-03-13
3
296 Views
Last Modified: 2014-03-18
I have fetched a list of images in a folder would like to loop through the list array of file names and add them to a html table that is being built on the fly. I need 3 new filenames with in each loop. How can  I do this?

He is some code to try help explain what I trying to do

Private Sub btnLoadBarcodes_Click_1(sender As Object, e As EventArgs) Handles btnLoadBarcodes.Click
        Dim myBarcode As New Neodynamic.SDK.Barcode.BarcodeProfessional()
        Dim barCode As String = Nothing
        Dim fileName As String = Nothing
        Dim objwriter As New StreamWriter(Application.StartupPath & "\barocode.html")

        Dim di As New DirectoryInfo(Application.StartupPath & "\Barcodes\")
        Dim dirs() As String = Directory.GetDirectories(Application.StartupPath & "\Barcodes\")
        Dim fi As FileInfo
        Dim file As String = Nothing
        Dim aryFi As FileInfo()
        Dim count As Integer = 0

        ''//CLEAR OUT OLD IMAGES
        aryFi = di.GetFiles("*.Bmp")
        For Each fi In aryFi
            fi.Delete()
        Next
        aryFi = Nothing

        ''// Generate images to be loaded into HTML table
        For Each oRow As DataGridViewRow In grdvUnPrinted.Rows
            If oRow.Cells("Print").Value = True Then

                barCode = oRow.Cells("DistrictOffice").Value
                barCode = barCode & oRow.Cells("CaseNum").Value
                barCode = barCode & " " & oRow.Cells("DocumentAnchor").Value

                fileName = oRow.Cells("DistrictOffice").Value
                fileName = fileName & oRow.Cells("CaseNum").Value
                fileName = fileName & "_" & oRow.Cells("DocumentAnchor").Value

                With myBarcode
                    .Symbology = Neodynamic.SDK.Barcode.Symbology.Code128
                    .TextAlignment = Neodynamic.SDK.Barcode.Alignment.AboveCenter
                    .Code = barCode
                    .TextAlignment = Neodynamic.SDK.Barcode.Alignment.AboveCenter
                    .CodeAlignment = Neodynamic.SDK.Barcode.Alignment.BelowCenter
                    .BarcodeUnit = Neodynamic.SDK.Barcode.BarcodeUnit.Millimeter
                    .BarHeight = 10
                    .BarWidth = 0.2
                    .Width = 700
                    .Height = 220
                End With
                Try
                    myBarcode.GetBarcodeImage()
                    myBarcode.Save(Application.StartupPath & "\Barcodes\" & fileName & ".Bmp", ImageFormat.Bmp)
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            End If
        Next

        ''//Create HTML table and load images
        aryFi = di.GetFiles("*.Bmp")

        objwriter.AutoFlush = True
        objwriter.WriteLine("<!DOCTYPE html>")
        objwriter.WriteLine("<html>")
        objwriter.WriteLine("")
        objwriter.WriteLine("<head>")
        objwriter.WriteLine("<title></title>")
        objwriter.WriteLine("<style media=""screen"">")
        objwriter.WriteLine("td {")
        objwriter.WriteLine("border: 1px solid black;")
        objwriter.WriteLine("}")
        objwriter.WriteLine("th, tr, td {")
        objwriter.WriteLine("padding: 10px;")
        objwriter.WriteLine("}")
        objwriter.WriteLine("</style>")
        objwriter.WriteLine("</head>")
        objwriter.WriteLine("")
        objwriter.WriteLine("<body>")
        objwriter.WriteLine("<table border=""0"" table style=""width:100%;"">")

        For Each fi In aryFi
            objwriter.WriteLine("<tr>")
            objwriter.WriteLine("<td width=400 height=80 align=center><img src=./Barcodes/" & fi.Name & " alt=""No Image Loaded""  width=200 height=80></td>")
            objwriter.WriteLine("<td width=400 height=80 align=center><img src=./Barcodes/" & fi.Name & " alt=""No Image Loaded""  width=200 height=80></td>")
            objwriter.WriteLine("<td width=400 height=80 align=center><img src=./Barcodes/" & fi.Name & " alt=""No Image Loaded""  width=200 height=80></td>")
            objwriter.WriteLine("</tr>")
        Next
        objwriter.WriteLine("</table>")
        objwriter.WriteLine("</body>")
        objwriter.Close()

        url = New Uri(String.Format("file:///{0}/barocode.html", Application.StartupPath))
        WebBrowser.Url = url

End Sub

Open in new window

0
Comment
Question by:Enigma_Koz
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 250 total points
ID: 39925939
If I understand correctly
       For Each fi In aryFi
            objwriter.WriteLine("<tr>")
            objwriter.WriteLine("<td width=400 height=80 align=center><img src=./Barcodes/" & fi.Name + "1" & " alt=""No Image Loaded""  width=200 height=80></td>")
            objwriter.WriteLine("<td width=400 height=80 align=center><img src=./Barcodes/" & fi.Name + "2" & " alt=""No Image Loaded""  width=200 height=80></td>")
            objwriter.WriteLine("<td width=400 height=80 align=center><img src=./Barcodes/" & fi.Name + "3" & " alt=""No Image Loaded""  width=200 height=80></td>")
            objwriter.WriteLine("</tr>")
        Next

Open in new window



or whatever you need to modify to get the three different file names
0
 

Author Comment

by:Enigma_Koz
ID: 39937090
That didn't work for me but it did put me on the right track.
0
 

Author Closing Comment

by:Enigma_Koz
ID: 39937093
was not what I really needed, but it did help point me in the right direction
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now