Solved

for each loop

Posted on 2014-03-13
3
306 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
[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
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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

623 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