Papa_Don 31 Posting Pro in Training

@pritaeas, I saw this but didn't understand what any of that meant. So I'm back to square one.

Some of my lack of understanding stems from the codes selected in the link select every field from the table. I'm not doing this as I'm selecting specific ones. Further, I'm unsure if SQL scripting allows for run time questions. Lastly, I'm so inexperienced in SQL, I'm not sure if I'm even asking the right kind of question.

Thanks for your interest and your teaching.

Don

Papa_Don 31 Posting Pro in Training

I've used your commands as you suggested. It works and appears to bring all of the data back. However I need to do a couple of things:

I need separate some of the 2014 data from the 2015 data. Specifically I need to do this:

LOS2014.RoomNites  RNLY --(name Room Nites Last Year)
LOS2014.Revenue    RevLY --(Revenue Last Year)
LOS2015.RoomNites  RNCY  --(Room Nites This Year)
LOS2015.Revenue    RevCY --(Revenue This Year)

How do I rename these columns using your method of joining the tables? Would I use a "Case" statement?

Papa_Don 31 Posting Pro in Training

@rch1231, I'm getting some data back, but not all. It seems it doesn't like what I'm trying to return and put in one table. Here's what I'm doing:

select      LOS2014.PROP_KEY            Property_Key,            
            LOS2014.ARV_TXN             ARVTXN,
            LOS2014.PROP_MASTER_ID      Property_NO,             
            LOS2015.PROP_KEY            Property_Key,            
            LOS2015.ARV_TXN             ARVTXN,
            LOS2015.PROP_MASTER_ID      Property_NO

from        LOS2014,
            LOS2015

Where       LOS2014.PROP_KEY = LOS2015.PROP_KEY

Order by    LOS2014.PROP_NAME,
            LOS2015.PROP_NAME

This is different from what you suggest, which may be why I'm only getting 2014 data back. What should my syntax be to get everything back and get it into the appropriot column?

Don

Papa_Don 31 Posting Pro in Training

Group,

I'm using TOAD to query the Oracle database. My better expertise is in VB.net. I have very little SQL experience.

My question: Can I create a variable in TOAD/SQL to prompt for a date(s)? Here is what I want to do:

Question 1: Enter Beginning Date (user to enter date value that looks like this: 01/01/2015)
Question 2: Enter Ending Date (user to enter ending date value, i.e. 04/30/2015)

I then will need to create two further variables based on these first two to represent the prior years dates (i.e 01/01/2014 and 04/30/2014). I would know how to do this in VB.net. Unfortunately I'm not sure about PL/SQL (or whatever it is that TOAD uses). Can you teach me how to do this?

Thanks for your assistance.

Don

Papa_Don 31 Posting Pro in Training

@rch1231, that makes sense to me. I'll give that a try and report back.

Don

Papa_Don 31 Posting Pro in Training

Hi group! I'll be up front and say I'm very new to SQL. I'm just now getting my feet under me in my new job. So I have lots of questions. I'll start simple (I hope).

I've created my own tables (2) that have multiple columns of data that looks something like this:

Property Name | Arrival Date | Room Nites | Revenue
Hotel 1 1/1/2014 1 $120
Hotel 1 1/1/2014 1 $115
Hotel 1 1/1/2014 1 $103

The above table is for January 2014 and the second one is for January 2015. It looks identical to the above except for the arrival dates.

I need to merge the data from these two properties into one table. In other words I need to have everything from both tables/columns into 1 table/column. Therefore the new table needs to look like this:

Property Name | Arrival Date | Room Nites | Revenue This Year | Revenue Prior Year
Hotel 1 1/1/2015 1 $120
Hotel 1 1/1/2014 1 $115
Hotel 1 1/1/2015 1 $103

Note - each instance of the data represents 1 reservation for 1 room for 1 room night. Thus the reason you'll see multiple listings for the same property on the same night.

So my question is, how to I do this?

In advance, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

My assumption is that it's required. I've been reading a good bit and the above code is the only thing that hasn't given me an error message. But keep in mind, this still didn't work. Given what I need to do, I have to divert from the default font and font size and change it to Arial Monospaced for SAP with a smaller font.

Thoughts?

Don

Papa_Don 31 Posting Pro in Training

FYI... I've now eliminated the error message. However it's not picking up the correct font. Here's what I've done:

Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream(newPDFName, FileMode.Create))
Dim bf As Font = FontFactory.GetFont("C:\Windows\Arial Monospaced for SAP", 7)
Dim fFont = New Font(bf)

I was hoping the code would fine the path of the correct font I need along with the size. But no luck here. I'm guessing it's still giving me the default font, although the size has gotten smaller.

Thanks again.

Don

Papa_Don 31 Posting Pro in Training

tinstaafl, Got it and tried it. It worked. Now the next issue: I need to change the font to "Arial Monospaced for SAP". Here's what I've tried:

Dim bf = FontFactory.GetFont("Arial Monospaced for SAP")
        Dim fFont = New Font(bf, 6)
        Dim objReader As New System.IO.StreamReader(saveRestran)
        If System.IO.File.Exists(saveRestran) Then
            row = 1
            Do While objReader.Peek() <> -1
                txtLine = objReader.ReadLine()
                lineEnd = Trim(txtLine)
                pdfDoc.Open()
                pdfDoc.Add(New Paragraph(txtLine, fFont))
                row = row + 1
                If row = 61 Then
                    pdfDoc.NewPage()
                    row = 1
                End If
                If lineEnd = "End of Report" Then
                    pdfDoc.Close()
                    objReader.Close()
                    Exit Sub
                End If
            Loop
            pdfDoc.Close()
        End If

It has accepted Dim bf = FontFactory.GetFont("Arial Monospaced for SAP"). However my error now comes on Dim fFont = New Font(bf, 6). Thoughts and ideas?

Thanks again,

Don

Papa_Don 31 Posting Pro in Training

Duh!! I knew that.... why I couldn't think of it, I chalk up to "olds-heimers....

Here's what I ended up doing:

If lineNo = 3 And programName = "(res.restran)" Then
      restranSave = "C:\Restran Conversion\Restran\" & propertyNo & "restran.txt"
      System.IO.File.Copy(fileName, restranSave, True)
      objReader.Dispose()
      System.IO.File.Delete(fileName)
      Call ConvertRestran()
      Call ConvertToPDF()
End If
Papa_Don 31 Posting Pro in Training

Group,

I'm converting a text file into a .pdf file using ItextSharp. The code below works perfectly to do this. Unfortunately the default font size is to large. I need to make it smaller. Here's my code:

Private Sub ConvertToPDF()
        '   Converting the Restran text file to a PDF file
        Dim row As Integer
        Dim lineEnd As String
        Dim txtLine As String
        saveRestran = hotelFolder & "\Restran\" & propertyNo & "Restran.txt"
        Dim newPDFName As String = hotelFolder & "\Restran\" & yearFolder & "\" & propertyNo & " - Restran " & formDate & ".pdf"
        Dim restranFile As String = hotelFolder & "\Restran\" & propertyNo & "Restran.txt"
        Dim restranText As String = File.ReadAllText(restranFile)
        Dim pdfDoc As New Document()
        Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream(newPDFName, FileMode.Create))
        Dim objReader As New System.IO.StreamReader(saveRestran)
        If System.IO.File.Exists(saveRestran) Then
            row = 1
            Do While objReader.Peek() <> -1
                txtLine = objReader.ReadLine()
                lineEnd = Trim(txtLine)
                pdfDoc.Open()
                pdfDoc.Add(New Paragraph(txtLine))
                row = row + 1
                If row = 61 Then
                    pdfDoc.NewPage()
                    row = 1
                End If
                If lineEnd = "End of Report" Then
                    pdfDoc.Close()
                    objReader.Close()
                    Exit Sub
                End If
            Loop
            pdfDoc.Close()
        End If

    End Sub

I've read multiple sites to find the appropriate VB.net code to change the font/font size. Every different code I've tried gives me an error. If you've got some thoughts, I would appreciate the help.

FYI.... I'm using Visual Studio 2010 (visual basic).

Thanks,

Don

Papa_Don 31 Posting Pro in Training

Group,

I'm using System.IO.File.Move to move an existing file into another folder. However it the program is stopping at this point with the error message "The process cannot access this file because is being used by another process". Unfortunately I can't find "the other process". For the record, I've also tried System.IO.File.Copy which works fine. However when I try to delete the original file, I get the same message.

Here's the full code I'm using:

                    Dim objReader As New System.IO.StreamReader(getRestranName(i))
                    fileName = getRestranName(i)
                    If System.IO.File.Exists(fileName) Then
                        Do While objReader.Peek() <> -1
                            txtLine = objReader.ReadLine()
                            prpName = Trim(Microsoft.VisualBasic.Left(txtLine, 30))
                            destinationFile = destinationFolder & "\" & Trim(Microsoft.VisualBasic.Right(fileName, 15))
                            If prpName = propertyName Then
                                System.IO.File.Move(fileName, destinationFile)
                            End If
                            Exit Do
                        Loop
                    End If

Is this issued happening because I have "fileName" still open as "objReader"? If this is the case, is there a way to close it while still in my loop?

As always, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Thanks, Jim. I'm going to give that one a whirl!

You're the man!

Don

Papa_Don 31 Posting Pro in Training

Group,

I'm using VB.net 2010 and would like to convert a text file into a PDF file.

In reading through the internet, it appears that I need to download a 3rd party .dll file. But is that needed? I see multiple PDF library references by right clicking the project name, choosing "Add Reference" and clicking the "COM" tab. These libraries include PDFFilter, PDFMAcad, PDFMaker for Visio, PDFMakerAPI, etc. Can (or should) any of these be used?

Thanks for your input!

Don

Papa_Don 31 Posting Pro in Training

djjeavons, I specifically used your idea as I have multiple files in the folder, some of which will be deleted and some that won't. So here's what I did:

                    If System.IO.File.Exists(fileName) Then
                        Do While objReader.Peek() <> -1
                            txtLine = objReader.ReadLine()
                            programName = Trim(Microsoft.VisualBasic.Left(txtLine, 14))

                            If lineNo = 3 And programName = "(avl.allover)" Then
                                fileSave = hotelFolder & "\Daily Reports\" & propertyNo & "Allover.txt"
                                System.IO.File.Copy(fileName, fileSave, True)
                                objReader.Dispose()
                                System.IO.File.Delete(fileName)
                            End If

                            If lineNo = 3 And programName = "(avl.dasrpt)" Then
                                fileSave = hotelFolder & "\Forecast\14 Day Forecast\" & propertyNo & "dasrpt.txt"
                                System.IO.File.Copy(fileName, fileSave, True)
                                objReader.Dispose()
                                System.IO.File.Delete(fileName)
                            End If

                            lineNo = lineNo + 1
                            If lineNo > 3 Then
                                lineNo = 1
                                Exit Do
                            End If
                        Loop

                    End If

I decided to "dispose" of the objectReader. This seamed to work better as I was to continue looking through the folder for other files.

As always, thanks for the help. The group here is the best!

Don

Papa_Don 31 Posting Pro in Training

Group,

I'm using the following code to read down to the third line of a text file. If it meets the criteria, I need to stop the read and then delete the file. However I'm finding it difficult to do this as everything I've tried has failed. Have you some thoughts on how I can do this?

                        Do While objReader.Peek() <> -1
                            txtLine = objReader.ReadLine()
                            programName = Trim(Microsoft.VisualBasic.Left(txtLine, 14))

                            If lineNo = 3 And programName = "(avl.allover)" Then
                                fileSave = hotelFolder & "\Daily Reports\" & propertyNo & "Allover.txt"
                                System.IO.File.Copy(fileName, fileSave, True)
                                ' Stop the reading of the file and delete the file now.  But how?
                                Exit Do

                            End If

In advance, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Hi group,

I'm using VB.net to convert an output file (text) from a Linux based program into a file that will easily read in Notepad. I found some code in VB.net to do this conversion for UNIX that works "OK" (meaning fair but not perfect). It looks like this:

txtLine = My.Computer.FileSystem.ReadAllText(RestranName)
' This begins to add the carriage returns in the appropriate places

txtLine = Replace(txtLine, vbLf, vbCrLf)
txtLine = Replace(txtLine, vbCr & vbCr, vbCr)
txtLine = Replace(txtLine, """", "")
' This writes the line to the file
My.Computer.FileSystem.WriteAllText(fileSave, txtLine, False)

The only issue (it's minor) is that it is adding a "ChrW(H2640)" character at the begining of each new page.

My question is: Would you know a better way to correct this so that it is formatted correctly and without the additional character?

In advance, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Shark1, I found the issue. I changed (folderName) to (getRestranName(i)). That solved it.

Papa_Don 31 Posting Pro in Training

Shark1, the problem I'm having is that StreamReader isn't reading "getRestranName(i)". My assumption is that the "i" is the problem. But I'm not sure why.

Papa_Don 31 Posting Pro in Training

Hi group,

I'm attempting to use a variable (i) to read the multiple files within a folder. However this doesn't seem to be working. Can you tell me what I'm doing wrong?

For i = 0 To counter
Dim objReader As New System.IO.StreamReader(getRestranName(i))

    If System.IO.File.Exists(folderName) Then
         Do While objReader.Peek() <> -1
            txtLine = objReader.ReadLine()
            If lineNo = 3 Then
               programName = Trim(Microsoft.VisualBasic.Left(txtLine, 10))

In advance, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

cgeier, I chose your first option. It worked like it was supposed to! Thanks for teaching me this. I knew there was something in there that would allow this. I just needed to be pointed in the right direction.

Thank you again!

Don

Papa_Don 31 Posting Pro in Training

Hi Group,

I attempting to save a file to a specific folder that is begins with the hotels property number. Currently I've manually listed the properties complete folder name in a text file. This is proving to be a management problem that needs to be fixed.

The code I'm using to find and save the file looks like this:

Using reader As New StreamReader("O:\IPSDATA\Property Folder Names.txt")
     While Not reader.EndOfStream
        Dim line As String = reader.ReadLine()
        If line.Contains(propertyNo2) Then
            hotelFolder = line
            Exit While
        End If
     End While
End Using

' setting the path name to save the converted file
fileSave = "O:\Revenue Management\Centralized Revenue Management Service\CRMS Hotels\" & hotelFolder & "\Restran\" & propertyNo & "Restran.txt"

You can see a line that looks for the folder using "line.Contains". Is there a way I can do the same thing when I'm looking through a directory? In other words, how can I look through the directory, "O:\Revenue Management\Centralized Revenue Management Service\CRMS Hotels\", find a folder that begins with (as an example) "0213" and then return the full name of that folder in the form of a string?

I'll continue to search the internet. But if you know how, please speak up!

Thanks,

Don

Papa_Don 31 Posting Pro in Training

Group,

I'm attaching the three files that are to be merged. The fourth is the merged file. While merging these files I again got the message that the program wasn't responding. However it eventually went through - just not as quickly as I thought it should.

I'm also attaching the complete code. Feel free to critique it. I'm sure there are things that I could have done more efficiently and cleaner. Feel free to offer suggestions.

Thanks for your interest. I certainly appreciate your help!

Don

Papa_Don 31 Posting Pro in Training

For what it's worth, everything I read says I should be able to run them. But I can't figure out how. It seems that my button is disabled and I can't click "Macros" to run the thing.

I will just keep trying.

Papa_Don 31 Posting Pro in Training

I'm using Excel 2010. On the "Review" tab, there is an icon to click (Share Workbook) that allows multiple people to be in the document at the same time. Individuals can make changes to the document even though it is open on the desktops of mutiple people.

Papa_Don 31 Posting Pro in Training

Hmmm..... I guess I didn't word that very well.

I wrote the macro BEFORE I saved it as a shared document. After I saved it as a shared document, I tried to run the macro. It didn't run. In fact, I couldn't even view the macro. Does this help?

Don

Papa_Don 31 Posting Pro in Training

Hi Group,

I've written a macro to save a copy of the spreadsheet at the end of each day. I tried to test it as a shared file and learned the macro wouldn't work. Is this normal for a shared document? If so, is there a way around this? How can I do this?

In advance, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Hello Group!

I've written an app that saves the updated info into a network file folder based on the property number (I'm in the hotel industry). Currently I have a text file with the individual folder names that I've hand written so the app knows where to store the data. However that's proven to be inefficient as properties are being added requently and, for some unknown reason, the folder names seem to change (probably because of someone's personal reason). I need to "fix" this. My thoughts are to:

1) write some code that will read the name of each folder in that network file path and store those names on my (now handwritten) text file
2) re-write the code in the app to use a wildcard to find where to store the data on its own. To clarify: all of our property folders begin with it's property number (i.e. "208" or "1203", etc.).

With either of these, I'm not sure if that can be done much less how to do it. If it's possible, I'd prefer to consider option 2.

If it helps, the property folders read as "1504 - FPbs Meriden" or "3363 - Aloft Charlotte Ballantyne". Is there a way that I use code to instruct the app to save the data in the folder just using "1504"?

In advance, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Sorry for the delay in responding. It's been an extremely busy week.

I believe the idea of debug.writeline is the best approach to finding where it may be stopping. I didn't think the program was overly complex either, but when it is deleting lines and merging more than two or three files, it really boggs down. On Monday I'll upload the three individual files that are to be merged. I'll also do a "after" merge upload for you to see.

Thinking out loud - I'll also drop the whole code into a text file so you can see everything I've done. Feel free to offer ideas on how to improve any portion of the program. Clearly I'm very inexperienced and have minimal training (two online courses in VB at my local college). I'd love to improve to the point that I might be useful to someone!

Group, thanks for all you do. You're the best!

Don

Papa_Don 31 Posting Pro in Training

Group,

You've helped me write a routine that merges and formats a text file when multiple files exist. The code is as follows:

                If fileCount = 3 Then
                    RestranName = getRestranName(0)
                    RestranName2 = getRestranName(1)
                    RestranName3 = getRestranName(2)
                    Dim readtxt() As String = File.ReadAllLines(RestranName)
                    'Deleted the actual file.
                    File.Delete(RestranName)
                    'Now time to read the array elements and save them in a file.
                    For i As Integer = readtxt.GetLowerBound(0) To readtxt.GetUpperBound(0) - 4
                        'Appending the line to the text file
                        My.Computer.FileSystem.WriteAllText(RestranName, readtxt(i), True)
                        If i < readtxt.GetUpperBound(0) - 4 Then
                            'Appending a new line into the text file.
                            My.Computer.FileSystem.WriteAllText(RestranName, vbCrLf, True)
                        End If
                    Next
                    My.Computer.FileSystem.WriteAllText(RestranName, pageCode, True)


                    Me.Cursor = Cursors.Default
                    Dim readtxt2() As String = File.ReadAllLines(RestranName2)
                    'Deleted the actual file.
                    File.Delete(RestranName2)
                    'Now time to read the array elements and save them in a file.
                    For i As Integer = readtxt2.GetLowerBound(0) To readtxt2.GetUpperBound(0) - 4
                        'Appending the line to the text file
                        My.Computer.FileSystem.WriteAllText(RestranName2, readtxt2(i), True)
                        If i < readtxt2.GetUpperBound(0) - 4 Then
                            'Appending a new line into the text file.
                            My.Computer.FileSystem.WriteAllText(RestranName2, vbCrLf, True)
                        End If
                    Next
                    My.Computer.FileSystem.WriteAllText(RestranName2, pageCode, True)
                    File.AppendAllText(RestranName, System.IO.File.ReadAllText(RestranName2))
                    File.AppendAllText(RestranName, File.ReadAllText(RestranName3))
                    File.Delete(RestranName2)
                    File.Delete(RestranName3)
                End If

                ' setting the path name to save the converted file
                fileSave = "O:\Revenue Management\Centralized Revenue Management Service\CRMS Hotels\" & hotelFolder & "\Restran\" & propertyNo & "Restran.txt"
                ' Getting date extension to save the file in a history 

                yesterday = Today.AddDays(-1)
                day = yesterday.Day.ToString
                month = yesterday.Month.ToString
                year = yesterday.Year.ToString
                year = year.Substring(2, 2)
                If yesterday.Day < 10 Then
                    day = "0" & day
                End …
Papa_Don 31 Posting Pro in Training

Here's the code that retrieves the 2 files and then strips the first file of it's last lines (that includes the phrase "End of Report"):

                    If fileCount = 2 Then
                    RestranName = getRestranName(0)
                    RestranName2 = getRestranName(1)
                    Dim readtxt() As String = File.ReadAllLines(RestranName)
                    'Deleted the actual file.
                    File.Delete(RestranName)
                    'Now time to read the array elements and save them in a file.
                    For i As Integer = readtxt.GetLowerBound(0) To readtxt.GetUpperBound(0) - 4
                        'Appending the line to the text file
                        My.Computer.FileSystem.WriteAllText(RestranName, readtxt(i), True)
                        If i < readtxt.GetUpperBound(0) - 4 Then
                            'Appending a new line into the text file.
                            My.Computer.FileSystem.WriteAllText(RestranName, vbCrLf, True)
                        End If
                    Next
                    My.Computer.FileSystem.WriteAllText(RestranName, pageCode, True)

After this is done I then merge the two files:

                    System.IO.File.AppendAllText(RestranName, System.IO.File.ReadAllText(RestranName2))
                    System.IO.File.Delete(RestranName2)
                    End If

I appreciate your ideas.

Papa_Don 31 Posting Pro in Training

I need to identify how the code identifies that a file is at the "eof" (end of file). Here's why:

On Monday's, I'm having to combine text files created over the weekend that will eventually be read and pulled into an Excel spreadsheet (generally there are three files). Using VB.net, I'm stripping the blank lines and the words "End of Report" from the end of the first two files before merging these together. The third file gets merged as is with no changes.

When I open the merged file (using Excel and VBA) to be read, I'm getting a error message at the beginning of the (technically) second report file (again, it's been merged with the first) that reads that it's "past the end of file". I'm trying to understand how it knows that as there is the merged data below that point. I'm trying to fix this so that it will continue to read to the last line of the report. Any thoughts?

In advance, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Bingo.... that worked!

Thanks guys. You're the best!

Don

Papa_Don 31 Posting Pro in Training

Group,

I've added the character at the end of the text file. It is doing this correctly. However this may not be the whole issue. It seems that when I append the next file to it, this next file begins at the very end of last line. I need for it to begin on the next line after. You can see that "FP Calgary" is at the end of the 1st text file (See the attached example).

Can you suggest what I need to write in to make that happen?

As always, thanks for your assistance.

Don

Papa_Don 31 Posting Pro in Training

Group,

Thank you. I've got a little more research and testing to do. But now you've pointed me in the right direction. I'll report back as to what I do. Thanks for your help again!

Don

Papa_Don 31 Posting Pro in Training

Group, Today I learned with Me.Cursor = Cursors.WaitCursor and Me.Cursor = Cursors.Default do. I've seen other programs, when running, a "message box" comes up and let's the user know what in the routine is happening. If it's possible to do in VB.net, I'd like to do the same thing. However I know I don't want to use a true MessageBox as I don't want the user to have to click OK each time. But it would be nice for them to see each "stage" of the progress being made. Is that possible? If so, how is this done. Can you suggest where I might see some examples?

In advance, thanks again for the help.

Don

Papa_Don 31 Posting Pro in Training

Oooooo.... I like this! Thank you again!!

This will prompt another question. But I'll write that in a new discussion.

Group, you're the greatest!

Don

Papa_Don 31 Posting Pro in Training

I do need to ask: What does Me.Cursor = Cursors.Default do? Since I am having to merge as many as 7 files into 1, will I need to insert this code each time I insert the pageCode character?

Thanks group!

Don

Papa_Don 31 Posting Pro in Training

Gentleman, as always, Thank You!

Papa_Don 31 Posting Pro in Training

Shark1, if I'm going to insert "Your Character", how is it I go about doing that? Minimalists tells me it is a UNIX character (Unicode character U+2640). Is there proper code to insert this like

Dim yourCharacter As (what?)
yourCharacter = 'Unicode character U+2640

Thanks....

Don

Papa_Don 31 Posting Pro in Training

Minimalist, I understand Notepad doesn't recognize the character as anything. However this character is clearly needed, as I must delete the last few lines of "file1" to combine it with "file2". Therefore I need to add that UNIX character at the end of "file1" to ensure the combined file formats correctly.

I probably should show you what I've written to format the file so you can better understand:

                txtLine = My.Computer.FileSystem.ReadAllText(RestranName)
                ' This begins to add the carriage returns in the appropriate places
                txtLine = Replace(txtLine, vbLf, vbCrLf)
                txtLine = Replace(txtLine, vbCr & vbCr, vbCr)
                txtLine = Replace(txtLine, """", "")

                ' This writes the line to the file
                My.Computer.FileSystem.WriteAllText(fileSave, txtLine, False)

If you have other ideas, I'm all ears!

As always, thanks for the help.

Don

Papa_Don 31 Posting Pro in Training

Group,

Some weeks back you helped me solve a formating issue with a text file that originates from a UNIX based program (see [https://www.daniweb.com/software-development/vbnet/threads/489626/remove-end-of-report-line-and-format-unix-text]).

While reviewing this newly formated data I saw that a character was place at the beginning of each page. Thus, I assume it does set the next page. However I'd like for you to look and confirm this. But more importantly, I need to know how to insert this character into my code. Because I am merging multiple reports together, I need to add this to the end of each report that is to be merged. I've attached a picture of this character for you to see.

My question is: What character is this, which VB code represents this character.

In advance, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Thank you, Minimalist and Rev. Jim. I'm glad I asked the question. This was great learning.

Don

Papa_Don 31 Posting Pro in Training

Minimalist, I have a few questions for you (I'm learning and want to understand):

I'm guessing that -

        If txt.GetType Is GetType(TextBox) Then
                If Len(txt.Text) > 0 Then
                numArr.Add(CInt(txt.Text)) ' assuming integers
        End If

looks at each textbox, checks to see if there is something in it, if there is it THEN adds the number to the array (after it converts it to an integer). Am I correct?

I presume then the statement before -

For Each txt As Control In Me.Controls

is the loop that looks at each of my 8 textboxes. Yes?

I'm not sure how this works here:

            For i = 0 To numArr.Count - 1
                Debug.Print(numArr(i).ToString)
            Next

Truthfully I'm not sure what you're actually doing here. Can you explain further?

Thanks for the help.

Don

Papa_Don 31 Posting Pro in Training

I'm writing a routine where the user can populate up to 8 textboxes with numbers. Since there is potential for these numbers to be unsorted, I want to sort these prior to saving. However it's probable that all of the textboxes will not be used. My challenge then is how to ignore the blank textboxes and not include them in the sort.

In my test, I've used 4 of the 8 boxes. It sorts perfectly - except it puts the blank textboxes first.

I've tried various versions of the following with no success. Are there any thoughts as to how to fix this?

        Dim IntArr(7) As String
        If tbxProp1.Text <> "" Then
            IntArr(0) = tbxProp1.Text
        End If
        If tbxProp2.Text <> "" Then
            IntArr(1) = tbxProp2.Text
        End If
        If tbxProp3.Text <> "" Then
            IntArr(2) = tbxProp3.Text
        End If
        If tbxProp4.Text <> "" Then
            IntArr(3) = tbxProp4.Text
        End If
        If tbxProp5.Text <> "" Then
            IntArr(4) = tbxProp5.Text
        End If
        If tbxProp6.Text <> "" Then
            IntArr(5) = tbxProp6.Text
        End If
        If tbxProp7.Text <> "" Then
            IntArr(6) = tbxProp7.Text
        End If
        If tbxProp8.Text <> "" Then
            IntArr(7) = tbxProp8.Text
        End If
        Array.Sort(IntArr)
        tbxProp1.Text = IntArr(0)
        tbxProp2.Text = IntArr(1)
        tbxProp3.Text = IntArr(2)
        tbxProp4.Text = IntArr(3)
        tbxProp5.Text = IntArr(4)
        tbxProp6.Text = IntArr(5)
        tbxProp7.Text = IntArr(6)
        tbxProp8.Text = IntArr(7)

In advance, thanks for your assistance.

Don

Papa_Don 31 Posting Pro in Training

Alicera Nz, I may have not be clear enough, so let me restate the issue:

The macro that opens "14D Scorecard.xlsx" works perfectly the first time. This same macro further down in the code closes this workbook after it is updated with new information.

The user will then make some changes to the primary document (this is the document the macro is in). The user will then start this macro again for the second time to open "14D Scorecard.xlsx", but this time the "14D Scorecard.xlsx" document does not open.

I'm not sure why "On Error Resume Next" is the problem. I'm using this to check to see if the report is open. If it is not open, I then want to open the report. Is there a better way to check to see if the report is open?

Don

Papa_Don 31 Posting Pro in Training

Hi group,

I've written some VBA code behind an Excel spreadsheet to check to see if another workbook is open. If it isn't open, I'm having the code open it for me. This works fine the first time the macro runs. However this same spreadsheet has a cell where a property number is changed. When this is done and it is time to run the macro for the second time, the second worbook never opens and I go into some kind of endless loop. Can someone suggest why this may be happening?

Here's the code I'm running to check to see if it's open and then to open it if it is not:

    wbFile = "O:\Revenue Management\RM -- Specialty Select Brands\Weekly - 14 Day Forecast\" & scoreCard
    On Error Resume Next
    Set wBook = Workbooks("14D Scorecard.xlsx")
    If wBook Is Nothing Then
        Exit Sub
    End If

FYI: "14D Scorecard.xlsx" is the second workbook that I've referred to above.

If you have some thoughts, I will greatly appreciate them. I've search the internet high and low and I can't find a reason why it would do this. Further, I'm not getting any kind of error message.

In advance, Thanks!

Don

Papa_Don 31 Posting Pro in Training

Shark 1, Yes, "Mastering Visual Basic 2010" is by Evangelos Petroutsos.

After reading earlier posts and then testing, it dawned on me that the code LineFromFile = sr.ReadLine() reads the next line. Further, While Not sr.EndOfStream is actually a loop. Therefore my code now looks like this:

            Dim sr As New StreamReader(filePath)
            Dim LineFromFile As String = Nothing
            Dim textRowNo As Integer = 0
            Dim arrival As String = Nothing
            Dim status As String = Nothing
            rowNumber = 5
            textRowNo = 1

            While Not sr.EndOfStream
                LineFromFile = sr.ReadLine()
                If (textRowNo >= 8) Then
                    arrival = Mid(LineFromFile, 1, 9)
                    status = Trim(Mid(LineFromFile, 11, 3))
                    typeText = Mid(LineFromFile, 18, 1)
                    guestName = Trim(Mid(LineFromFile, 23, 28))
                    roomType = Trim(Mid(LineFromFile, 54, 5))
                    rateSched = Trim(Mid(LineFromFile, 60, 10))
                    rateText = Mid(LineFromFile, 71, 11)
                    roomRate = Val(rateText)
                    CCtype = Mid(LineFromFile, 93, 2)
                    CCNo = Mid(LineFromFile, 98, 9)

                    textRowNo = textRowNo + 1

                    LineFromFile = sr.ReadLine()
                    departure = Mid(LineFromFile, 1, 9)
                    source = Trim(Mid(LineFromFile, 48, 5))
                    agent = Trim(Mid(LineFromFile, 122, 9))

                    sheet.Cells(rowNumber, 1).Value = arrival
                    sheet.Cells(rowNumber, 2).Value = departure
                    sheet.Cells(rowNumber, 3).Value = status
                    sheet.Cells(rowNumber, 4).Value = typeText
                    sheet.Cells(rowNumber, 5).Value = guestName
                    sheet.Cells(rowNumber, 6).Value = roomType
                    sheet.Cells(rowNumber, 7).Value = rateSched
                    sheet.Cells(rowNumber, 8).Value = roomRate
                    sheet.Cells(rowNumber, 9).Value = CCtype
                    sheet.Cells(rowNumber, 10).Value = CCNo
                    sheet.Cells(rowNumber, 11).Value = source
                    sheet.Cells(rowNumber, 12).Value = agent

                    departdate = CDate(sheet.Cells(rowNumber, 2).Value)
                    arrvdate = CDate(sheet.Cells(rowNumber, 1).Value)
                    los = (departdate.Subtract(arrvdate))
                    sheet.Cells(rowNumber, 13).Value = los.Days
                    rowNumber = (rowNumber + 1)
                    textRowNo = (textRowNo + 1)

                    LineFromFile = sr.ReadLine()
                    textHead = Mid(LineFromFile, 51, 11)
                    If textHead = …
Papa_Don 31 Posting Pro in Training

Rev Jim,

I've purchased "Mastering Visual Basic 2010" but I don't see anything that suggests converting VBA code. I've also taken a couple of college courses in VB.net which were awesome. The codes suggestions above look pretty good. The next thing for me to do is to try them and build around them.

My assumption was I'd use StreamReader as it would allow me to loop through it which is exactly what I need to do. My biggest challenge comes when I get further down the text file and I start seeing header information from the actual output file that our system is creating (it's actually a multi-page report). I have to scroll through those 7 lines again as I did at the very beginning.

With these suggestions, I'll work from here and post what I actually do for someone looking to do the same thing in the future.

Don

Papa_Don 31 Posting Pro in Training

Hello Group,

I'm trying to convert some VBA code into VB.net. Here is that VBA code:

    Open filePath For Input As #1          ' filePath = the text file I need to read
    Do Until textRowNo = 8
        'discard these first 7 rows...
        Line Input #1, LineFromFile
        'this is the row counter
        textRowNo = (textRowNo + 1)
    Loop

Ultimately I need to throw out the first seven rows of the text file. But is there a VB.net equivalent to Open filePath For Input As #1?

After this is done, I want to continue and begin at line 8 and do the following:

        Do Until EOF(1)
        Line Input #1, LineFromFile
        arrival = Mid(LineFromFile, 1, 9)
        status = Trim(Mid(LineFromFile, 11, 3))
        typeText = Mid(LineFromFile, 18, 1)
        guestName = Trim(Mid(LineFromFile, 23, 28))
        roomType = Trim(Mid(LineFromFile, 54, 5))
        rateSched = Trim(Mid(LineFromFile, 60, 10))
        rateText = Mid(LineFromFile, 71, 11)
        roomRate = Val(rateText)
        CCtype = Mid(LineFromFile, 93, 2)
        CCNo = Mid(LineFromFile, 98, 9)
        textRowNo = (textRowNo + 1)

Here I'm moving specific portions of the line into the various variables. I then need to do the same for Line 9:

        If EOF(1) Then Exit Do      'checks to see if it's the end of file

        Line Input #1, LineFromFile
        departure = Mid(LineFromFile, 1, 9)
        source = Trim(Mid(LineFromFile, 48, 5))
        agent = Trim(Mid(LineFromFile, 122, 9))

And now I'm reading line 10

        Cells(rowNumber, 13).Value = los
        rowNumber = (rowNumber + 1)
        textRowNo = (textRowNo + 1)

' Row 10 …