Jump to content
Sign in to follow this  
PcExpert

Array problems

Recommended Posts

PcExpert

I have a program which reads things from a textfile. The textfile can be like this:

Protection: 0 uur

but it can also be like this:

Protection: 2 uur (tot 16-06 / 14:00u)

My current script gives errors when you dont have protection anymore, so when its like this: Protection: 0 hours

My Script (a part of):

$beschermingstr = StringSplit(FileReadLine("tekst.txt", $l_bescherming), ": ", 1)
$beschermingstr2 = StringSplit($beschermingstr[3], " (", 1)
If $beschermingstr2 = Not @error Then
 If StringInStr($beschermingstr2[2], "tot") Then
 GUICtrlSetData($lbl_bescherming, "Bescherming: " & $beschermingstr2[1] & @CRLF & "(" & $beschermingstr2[2])
Else
  GUICtrlSetData($lbl_bescherming, "Bescherming: 0 uur")
EndIf
.

.

$l_bescherming just stands for the line the text is on and $beschermingstr[3] stands for everything after 'bescherming:'

How to solve this? While you have protection everything works fine without any errors, but once you dont have protection anymore (Bescherming: 0 uur) it returns errors (because $beschermingstr2[1] and $beschermingstr2[2] dont exist anymore) . I thought that it should then read the else statement and do the things that are in there.

Edited by PcExpert

Share this post


Link to post
Share on other sites
oMBRa

something like this:

Pseudo-code

$beschermingstr = StringSplit(FileReadLine("tekst.txt", $l_bescherming), ": ", 1)
if stringinstr... search if there is the parenthesis, if yes
$beschermingstr2 = StringSplit($beschermingstr[3], " (", 1)
 GUICtrlSetData($lbl_bescherming, "Bescherming: " & $beschermingstr2[1] & @CRLF & "(" & $beschermingstr2[2])
Else
  GUICtrlSetData($lbl_bescherming, "Bescherming: 0 uur")
EndIf

Share this post


Link to post
Share on other sites
GreenCan

Hi PcExpert,

I am not sure why you want to complicate things but a simple StringInstr does the job:

$beschermingstr = FileReadLine("tekst.txt", $l_bescherming)

If StringInStr($beschermingstr,"Protection: 0 uur")>0 Then

ConsoleWrite("Alarm" & @CR)

Else

ConsoleWrite($beschermingstr & @CR)

EndIf

Greencan


Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.