Solved

for each loop

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help on C# Linq query on object 6 53
I need help embedding Base64 Images using VB.Net - When image is a .jpg 2 43
ASP.NET 5 Templates 2 68
SQL Exceptions 3 40
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now