How to read all values from .INI section using Team Developer

Discussion forum about all things Team Developer 5.x and 6.x
afcneo
Brazil
Posts: 5
Joined: 03 Jan 2019, 12:35
Location: Brazil

How to read all values from .INI section using Team Developer

Post by afcneo » 16 Jan 2019, 13:44

Hello,

How to read all values from .INI section using Team Developer?


Regards
Anderson Costa

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2928
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: How to read all values from .INI section using Team Developer

Post by Dave Rabelink » 16 Jan 2019, 14:40

Use VisProfileEnumStrings (from vtmisc.apl) to get all keys from a section as an array.

Then use SalGetProfileString and SalGetProfileInt to get the values for each key in the array.

Code: Select all

Set nTotalKeys	= VisProfileEnumStrings( "MySettings.ini", "SECTION1", saKeys )

Set nCount = 0
While nCount < nTotalKeys
	Call SalGetProfileString( "SECTION1", saKeys[nCount], "", sValue, "MySettings.ini")
	Set nCount = nCount + 1
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

afcneo
Brazil
Posts: 5
Joined: 03 Jan 2019, 12:35
Location: Brazil

Re: How to read all values from .INI section using Team Developer

Post by afcneo » 17 Jan 2019, 15:49

Perfect, thanks!

Is it possible to get too the keys name?

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2928
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: How to read all values from .INI section using Team Developer

Post by Dave Rabelink » 17 Jan 2019, 21:58

afcneo wrote:
17 Jan 2019, 15:49
Is it possible to get too the keys name?
Do you mean keys or sections?

Code: Select all

[Section1]
Key1 = Value
Key2 = Value

[Section2]
Key1 = Value
Key2 = Value
As given in my previous post, the key names (Key1, Key2 etc) can be enumerated using VisProfileEnumStrings
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

afcneo
Brazil
Posts: 5
Joined: 03 Jan 2019, 12:35
Location: Brazil

Re: How to read all values from .INI section using Team Developer

Post by afcneo » 17 Jan 2019, 23:57

Soon after I sent the message, I saw where to get the names, it was foolish of me.

Last question, which function represents the Split? To separate words with a comma and put in an array.

Sorry for asking these simple questions, I'm new to developing with Team Developer and I'm still a little lost. :D

MattiU
Finland
Posts: 4
Joined: 21 Mar 2017, 06:16
Location: Helsinki, Finland

Re: How to read all values from .INI section using Team Developer

Post by MattiU » 18 Jan 2019, 06:22

nNumTokens = SalStrTokenize ( strSource, strStartDel, strEndDel, strTokenArray )

Parses a string into substrings (tokens) based on specified start and end delimiters.

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2928
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: How to read all values from .INI section using Team Developer

Post by Dave Rabelink » 18 Jan 2019, 13:52

I created an article for this on the WIKI.

It shows how to parse an INI file using a feature which is not that well known: enumerate section names.

https://wiki.tdcommunity.net/index.php/ ... _INI_files
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

afcneo
Brazil
Posts: 5
Joined: 03 Jan 2019, 12:35
Location: Brazil

Re: How to read all values from .INI section using Team Developer

Post by afcneo » 21 Jan 2019, 18:13

Thanks for your help! Gradually I am able to learn and create my project.

I don't know if I'm not looking correctly, but I'm having difficulty to found certain functions.

The project I want to do is read the XML from a database and put the values in another database. The fields are defined dynamically through the INI file and created in a table in the program, but after creating the columns I am not finding now the function to set the values.

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2928
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: How to read all values from .INI section using Team Developer

Post by Dave Rabelink » 21 Jan 2019, 19:19

To put data into a child table.

Example below is for a table having name tbl1 having two columns names col1 (string) and col2 (number)

First, insert a new row in the table. It is appended to any existing rows in the table due to TBL_MaxRow flag.

Code: Select all

Set nRow = SalTblInsertRow( tbl1, TBL_MaxRow )
nRow will have the row number of the newly inserted row. The first row will have row number 0 (zero).

Next, to be able to use the column names and set the data for the inserted row, you need to set the table context row number.

Code: Select all

Call SalTblSetContext( tbl1, nRow )
And then you are able to set the values for each column

Code: Select all

Set tbl1.col1 = "My text"
Set tbl1.col2 = 1234

To insert another row, just repeat the steps.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

afcneo
Brazil
Posts: 5
Joined: 03 Jan 2019, 12:35
Location: Brazil

Re: How to read all values from .INI section using Team Developer

Post by afcneo » 26 Jan 2019, 23:50

Thanks! Because the columns are dynamic, this method didn't work, but I was able to set the values using:

Code: Select all

Call SalTblSetColumnText( tblMain, nID, sValue )

FRBhote
India
Posts: 2216
Joined: 09 Mar 2017, 05:32
Location: Hyderabad, India

Re: How to read all values from .INI section using Team Developer

Post by FRBhote » 04 Feb 2019, 07:16

What could I be doing wrong?

Both give me a null return for the entry:
[win32client.ws32]
;serverpath=server1,219.64.39.23,2155/*
serverpath=server1,192.168.3.10,2155/*

Code: Select all

Call SalGetProfileString( '[win32client.ws32]', 'serverpath', '', sgCommit, 'SQL.INI' )

Call SalGetProfileString( 'win32client.ws32', 'serverpath', '', sgCommit, 'SQL.INI' )

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2928
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: How to read all values from .INI section using Team Developer

Post by Dave Rabelink » 04 Feb 2019, 07:29

Did you try to use the full path to the SQL.ini file?
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

FRBhote
India
Posts: 2216
Joined: 09 Mar 2017, 05:32
Location: Hyderabad, India

Re: How to read all values from .INI section using Team Developer

Post by FRBhote » 04 Feb 2019, 08:20

Yes I did. Same result.

WIKI_Parse_INI_ANSI.apt appears to work, but the output has repeating values for the below. Can't figure out why sValue remains the same in
Call SalGetProfileString( saSections[nCountSections], saKeys[nCountKeys], "", sValue, psINIFile )
[win32client]
clientname=FRB
setzerolengthstringstonull=on


[win32client.dll]
;comdll=sqlapipe
;comdll=sqlspx32
;comdll=sqlntnbi
comdll=sqlodb32
comdll=sqlora32
comdll=sqlws32
;comdll=sqlwsspx

[win32client.apipe]
;debug=15,client.dbg

[win32client.ws32]
;serverpath=server1,219.64.39.45,2155/*
serverpath=server1,192.168.3.10,2155/*
Untitled.png
Anyway, it doesn't matter. I had planned on writing a file using the server IP, but then realised that there were no rights to do that. Using a dummy database instead of a file.

Came across a funny situation: If SqlConnect fails (the DB doesn't exist) then when SAM_SqlError returns FALSE (I don't want any messages), the If SqlConnect also gets FALSE!
You do not have the required permissions to view the files attached to this post.

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2928
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: How to read all values from .INI section using Team Developer

Post by Dave Rabelink » 04 Feb 2019, 09:32

The problem is that SQL.ini does not conform to the proper INI specs.

The SAL functions are not able to handle duplicate key names within the same section.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

FRBhote
India
Posts: 2216
Joined: 09 Mar 2017, 05:32
Location: Hyderabad, India

Re: How to read all values from .INI section using Team Developer

Post by FRBhote » 04 Feb 2019, 10:54

I see. Thanks.

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests