Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

for each loop

Posted on 2014-03-13
3
Medium Priority
?
307 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 500 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

721 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