Solved

for each loop

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET Calendar Control 5 54
Trouble installing msi file with msiexe.exe 2 51
CSS question 16 63
GUID's in SQL Server 4 31
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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