Embed console in form - vb.net

TL;DR:
Is there a way to embed a console inside a form, so it becomes a part of it?
Scenario:
I am writing a chat-application with client, server and database using Windows Forms in VB.NET. The server should log all communication it has with clients in a textbox.
The Problem:
So far that would not be a problem - If there wasn't a maxlength for strings! I expect this server to almost never stop (Okay, there is always some point where it does.. but lets ignore that). So if i go for Textbox1.Text &= vbnewline & "Something" it will some day reach this length and run into an exception each time something is about to be logged. I also don't want to just remove the first characters of the string.
My Idea for a solution:
My idea for a work around: Use a console instead of a simple textbox and embed it into the form, so it becomes a part of it. Is there a simple way to do that? By simple I mean that I should have to write thousands of lines of code to achieve that goal.
I am open minded for different ideas and ways to do so as well.

Why not just log your chat to file (you could create a file per day)?
Dim filename = String.Format("C:\Temp\{0:yyyy-MM-dd}-log.txt", DateTime.Now)
My.Computer.FileSystem.WriteAllText(filename, "line of text", True)
Then to display it - use a ListBox and append each new line to the end of the listbox? Each time you append, you could check how many items are in the listbox and remove the first 100 if you are over 1000 as an example.

Related

Applescript in reverse?

& thanks for all the tips i've had here... this site is ace!
My question is, basically, how to correctly write my script. I've written an applescript, that works great for 1 variable, but i'll need to add hundreds of variables, and that'll currently mean adding hundreds of "if" statements.
So my script queries a FileMaker database & receives an input field (which is variable), i then want to open a the related textEdit file & read the text.
ie... FileMaker Pro returns "123", so i want to open textEdit file "123".
However, my script currently says If text returned is "123" then do this, else if text returned is "234" do this, else if text returned is "345" do this. To write this script with hundreds of "Ifs" doesn't make sense, but i can't get my head around swapping my script to say - returned value is "123" so use file 123.
Does anyone have a suggestion?
Thanks

How to keep all webclient text in one line in Skype?

I'm having a issue with visual basic 2012 Webclients. I'm trying to gather information from a website. Then upload it to a Skype chat. On the website, the text goes in separate lines. Example:
Hello.
How Are You?
Good Thanks.
When I run the application, it displays the text in a odd way. It displays it like this:
<br>Hello<br>how are you&<br><br>good<br>
Here is the code. (This project is based around a Skype Bot, So I will need to blank out the api for this.)
ElseIf msg.StartsWith("cloudflare ") Then
c.SendMessage("SkypeBot >" + vbNewLine +
("" + New WebClient().DownloadStringTaskAsync("api" & msg.Replace("cloudflare ", ""))))
The issue is based around .DownloadStringTaskAsync I believe. Help with this issue will be highly appreciated.
EDIT: I also know about "You need to use HTML on a web page to get line breaks. For example "" will give you a line break."
but I'm unsure where to insert it and how to use it in that code.
My VB.NET knowledge is a little rusty, but can you not use something like this (C# code):
string[] arrayOfText = welcomeText.split("<br>");
Then you can do whatever you want with the text. Stick it back together, but with spaces instead of < br>
Alternatively you could use the .replace function?

VB Code explanation? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Hey can someone explain this VB (Visual basic) code in a way thats simple for everyone to understand even minimal to no coding experience but still explains each section, also what dim and open do. Thanks!
Dim studentname As String
Dim intMsg As String
Private Sub Command1_Click()
‘To read the file
Text1.Text = ""
Dim variable1 As String
On Error GoTo file_error
Open "D:\Liew Folder\sample.txt" For Input As #1
Do
Input #1, variable1
Text1.Text = Text1.Text & variable1 & vbCrLf
Loop While Not EOF(1) Close #1
Declare a student name variable that we will call studentname as a string. Think of variables as you would do x and y in an algebraic equation. They are simply names for things of a particular type. In a maths equation x and y are numbers. A string is a basically a sequence of characters, such as words, numbers, or any other arbitrary data. "Moo-Juice" is a string, for example - delimited by the " characters.
Declare a message called intMsg as a string.
Subroutine "Command1_Click", called when the button (presumably) Command1 is clicked by the user. Subroutines are functions and are where you either put common code that you wish to re-use, or in the case of languages such as this, to respond to events that have occurred. Events in GUI applications come in various different flavours, this one is called when the user clicks a button. Others include MouseMove, KeyUp, KeyDown. Responding to these events allows your code to do stuff.
Set the Text1 control's Text property to an empty string (clear it). Controls on a form (both the text box and the button are examples of controls), have properties. The Text property is where a Textbox control stores what you can see in the textbox. Controls generally have a whole bunch of properties. Left denotes where it is on the form with regards to the horizontal position. Font specifies want font to use, etc, etc. There are many different GUI systems, and beyond VB6 and in the .NET environment there are Windows Forms, and WPF (Windows Presentation Foundation). In other languages there are as many GUI systems as you can care to think of.
Declare variable1 as a string.
Within this subroutine (Command1_Click), should an error occur go to the file_error label that appears not to be in your code snippet so we can assume it is farther down, beyond the loop. GoTo does exactly what it says on the tin - it jumps to the label specified and execution continues there. On Error tells visual basic what to do if an error occurs, and in this case it is saying "Go there if something goes awry".
Open the file specified, in read mode, assigning it file handle #1 for future reference. File handlers, like variables, are a way of identifying a file we want to do something with. Without file handlers (in VB6) if I open multiple files at the same time, how does the system know which one I want to write to? By saying "Open this file, and I'll refer to it as #1", we can tell the system which file we want to play with at any particular point in time.
Begin a loop. There are many loop constructs, and the verbosity of VB6 (and BASIC in general) allows you to see what kind of loop you're doing. This is a Do loop. It will execute at least once, with the condition at the end being checked each iteration. Should that check return true, the loop stops. Other loop types include For (for fine-grained control over steps, and how many iteration. Other languages allow more expressive boolean logic to determine the exact lifetime of a for-loop), and While which is similar to do, but the check is performed at the top, so it may run zero times if the condition fails immediately.
Read in a line from file handle #1 in to our string variable variable1. Remember we've told it which file handle to use and so the system knows where to read the data from.
Append this to the text box we emptied earlier, with a carriage-return & line-feed. Given that we are reading line-by-line, we're preserving the line-endings when putting the text in to the text box. Appending means we're keeping what was there and adding to it.
Keep doing this until we've reached the end of the file. The EOF() function takes a file handle and says whether we've reach the *E*nd *O*f the *F*ile. Remember that the end of our loop terminates if the expression is true. Well, EOF() returns true if we've reached the end of the file. A good time to stop reading it, don't you think? :)
Close the file handle. Enough said! :)
To Summarise
This code snippet reads in a file line-by-line and puts the contents in a textbox, preserving the line-endings.
Issues
intMsg is never used.
Neither is studentname
As mentioned earlier, you're missing the file_error label and the end of the sub-routine (End Sub).

VB 2010: ScrollToCaret won't work on plain textbox but will with rich text box

I have written an application in VB 2010 that generates log files, and I wanted to add a feature to view the log files without leaving the app. This was done, naturally, by adding a form with a text box and loading in the file.
Sometimes these files get plenty big, so I was looking for a way to just show the most recent entries -- i.e., the last few lines. I got that figured out (using a pretty cool method that works really fast without iterating through all the lines of text).
Just to make it convenient, I wanted to make it display the very bottom of the text box, so ScrollToCaret() was employed. However, in this particular text box, the ScrollToCaret() function didn't work, no matter how I tried to implement it. If I use a RichTextBox, it works fine, and if that's what I need to do, that's how I'll do it. But I have to know why it wouldn't work in a regular text box.
Here's my code:
Dim intLineCount As Int64 = IO.File.ReadAllLines(strFileName).Length
Dim intStartPosition As Int64 = intLineCount - 1000
Dim intPositionLoop As Int64
Try
Dim strAllLines() As String = File.ReadAllLines(strFileName)
For intPositionLoop = intStartPosition To intLineCount
txtViewLogs.AppendText(strAllLines(intPositionLoop - 1) & vbNewLine)
Next
Catch ex As Exception
End Try
txtViewLogs.Focus()
txtViewLogs.ScrollToCaret()
As this shows, this will display the last 1000 lines of the log file. When the file is completely loaded, the caret is already at the end of the file, so there was no need to set the SelectionStart point to the end of the file, but I even tried that, and no luck.
In order to eliminate the possibility that some property of the text box could have been accidentally changed, I deleted the text box and added another one, taking care not to make any accidental changes to the properties.
Anyone have any idea why it's like this? As I said, if I have to stick with a rich text box, that's what I'll do, but it kills me not knowing why this is doing that. I know I've used this in other applications, but I can't see why it won't work with this one.

Add multiple blank lines to a Report from TextBox?

I have an Access Database linked to a Crystal Report (2011). The Report has many Sections, one Group, as well as several Sub Reports.
Each Sub Report is in its own Section on the main Report. Each Section/Sub Report is set to "Keep together on one page."
What my boss is looking for is a way to add space "on-demand" to the end of any section. In other words, he wants the report to be a word document that he can freely add lines to.
I know this is not exactly possible. I do realize that you can export a Report as a .doc File, but that takes extra steps and we are trying to automate this as much as possible.
What I am considering is a TextBox (TextBox1) in Access that allows you to type in a number and adding a that number of blank lines to a different TextBox (TextBox2) (E.g. if you type 3 in TextBox1 then the value for TextBox2 would be something like "". Then referencing TextBox2 in a formula in the Report using HTML interpretation.
Is there an easy way to do this?
Does anyone have any better suggestions?
If you haven't already, I'd try giving him/her a version of the report with "extra" blank space already included. Another option might be doing page breaks after the sub-reports. Make sure it looks good to you and then present it.
But, to do the variable blank spaces, I'd use a Crystal parameter (or multiple Crystal parameters). This way, everything is in one place. If the boss decides there should be one more line, he/she can just hit refresh and change the parameter rather than going back to the Access form. Once you have the parameter, add a formula to the form when you want the variable spaces, and set it to "can grow". The actual formula would be something like:
Local NumberVar i;
Local StringVar out := "";
for i := 1 to {?BlankLines} do
out := out + chr(13) + chr(10);
out;