Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need help in working out a logic in my scroller application that would make it more resourceful. Its designed with vb.net 2012. The app has 2 labels. One for scrolling contents and the other to display something else like a header.

The text file has contents for different sections. See text file sample below:

ITD - 05/MAY/17 1:20pm - THERE WILL BE TEMPORARY NETWORK OUTAGE IN COMPUTER ROOM FROM 10AM FOR MAINTENANCE WORK

HSE - 01/MAY/17 1:20pm - SAFETY ALERT: ONGOING CONSTRUCTION WORK AT THE WALKWAY. PLEASE DO NOT USE THE WALKWAY TO AVOID INJURIES

GENERAL - 07/Apr/17 2:00pm - PUBLIC HOLIDAYS HAS BEEN SCHEDULED FOR OCT 1st 2017

A distinctive phrase is placed at the beginning of each sentence to identify the source of the information.

The scroller application pulls information from the text file with the file.readalltext method. See code below

VB
lblScroller.Text = File.ReadAllText(FILE_NAME).Replace(vbCr & vbLf, " ")


Then a code scrolls the contents in the label from right to left continuously.

I want to know how to check when a particular text or string scrolls into display on the label control and then the other label would also change to the name of the section.

For example, the app would check when the string HSE scrolls into display, the other label would change to HSE. Users will then know that the information scrolling is from HSE. When the string GENERAL scrolls in, the label then changes to GENERAL so users would know that the information scrolling in is from GENERAL.

What I have tried:

I had taught of using different text files for each section or departments but it didn't work effectively because I had to use timers for different streamreaders for each text files. But if the content of a text file is large then the timer would not allow all the content to finish scrolling before it elapse and triggers the next streamreader.

I have tried using the 'contains' method to check for unique phrase and it always return true because streamreader loads the whole content of the file into the label control at once.

If I could be able to programmatically tell when a phrase or word just scrolls in from the beginning then the other label would indicate the source of the information.

Its like the normal TV Station scrolling news with different sections. E.g When sports information is scrolling in, a label at the far left changes to SPORTS.
Posted
Updated 4-May-17 1:53am
Comments
Ralf Meier 4-May-17 6:25am    
You wrote a lot but for me it's not clear what you want to do ... sorry.
I think it's necessary to improve your question with the relevant code-part's (use the 'Improve Question' function for this)

1 solution

I am assuming you have a timer to action the scrolling. Something like this works:
C#
private string[] distinctivePhrases = {"HSE", "GENERAL"};
private void Form1_Load(object sender, EventArgs e)
{
    Scrll = -1;
    tmr = new Timer();
    tmr.Tick += TimerTick;
    tmr.Interval = 200;
    tmr.Start();
}
private void TimerTick(object sender, EventArgs e)
{
    var iLmt = ScrollString.Length - (Scrll++);
    if (iLmt < maxChars) Scrll = 0;

    lblScroller.Text = ScrollString.Substring(Scrll, maxChars);
    foreach (var phrase in distinctivePhrases.Where(phrase => lblScroller.Text.Contains(phrase)))
    {
        lblHeader.Text = phrase;
        break;
    }
}
I suggest that you demark the distinctive phrase a bit more distinctively e.g. prefix with "**" so that having the word "general" in the text does not trigger a header change. It also makes the code to change the header a little simpler
C#
private void TimerTick(object sender, EventArgs e)
{
    var iLmt = ScrollString.Length - (Scrll++);
    if (iLmt < maxChars) Scrll = 0;

    var scrollText = ScrollString.Substring(Scrll, maxChars);
    lblScroller.Text = scrollText;

    if (!scrollText.StartsWith("**")) return;
    lblHeader.Text = scrollText.Substring(2, 
        scrollText.IndexOf(" ", StringComparison.InvariantCultureIgnoreCase) - 1);
}
Note the Substring starts at element [2] to ignore the "**".
 
Share this answer
 
Comments
Onyebuchim 12-Jun-17 4:42am    
Thanks a lot. I'll give it a try

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900