Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Strange Error with Duplicate Naming

Author
Message
Bulsatar
15
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 20th Apr 2011 07:40
Hello Everyone,

I was working on some code to create an InStr() function (i know, there are others out there, but I am new to dbpro and wanted to exercise my mind a little) and I got it working. I saved it, re-opened it and then got this error message when compiling:
Compilation Failed: The name 'InStr' duplicated in the program at line 128
However, there is no line 128! Here is the entire code of the program...


Thanks for any help, always appreciated!
Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 20th Apr 2011 09:55 Edited at: 20th Apr 2011 09:56
The problem is that instr() is a reserved word in DBPro, in other words it is a built in function of DBPro so you have a duplicate problem. The solution is to change the name of the function, simple.

So try this:


I changed your function name of Instr to In_str.

A clever person solves a problem, a wise person avoids it - Albert Einstein
Bulsatar
15
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 20th Apr 2011 15:51
Oh...I thought that InStr was one of those functions that got left out (at least that is what the searches I did here told me). Was I incorrect and dbpro has it's own InStr and RevInStr functions????
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Apr 2011 15:53
It isn't a reserved word, unless you have either my plug-ins or STYX installed, each of which add that command to the system.

Bulsatar
15
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 20th Apr 2011 19:53
I downloaded your plug in set, but I don't think I have installed it yet. And especially since it worked before I saved it....hhmm, very strange....
Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 21st Apr 2011 01:16
Sorry for the confusion Bulstar, I just typed in "instr" in an empty project and it went blue so I thought it was a command everyone had. Next time I come across a problem like this I'll check where the command comes from .

I'm assuming that the problem still occurs? Well the only time I remember getting a duplicate function error was when I had multiple source files and used the #include command. Is that the whole project you are showing or just a small piece of a project?

A clever person solves a problem, a wise person avoids it - Albert Einstein
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Apr 2011 01:21
Yes, that usually happens when people both add the included file to the project as an extra file, and then also #INCLUDE it too.

Bulsatar
15
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 21st Apr 2011 18:30
Well, I tried your hodgey and it did work. I also did a little more investigation. I commented out the InStr function but kept the InStr code in the loop. DBpro then recognized it as just a normal variable, no Intellisense which normally happens when a function is recognized.
I don't have any #include or anything. The code I posted above is all of it, from line 1 to the end of the code. I also checked and I did not install your plug-ins Ian so I am not getting conflict with that.
I am at work right now, but I think I will try starting a new project and retyping the code from scratch, maybe there is something "stuck" in the save file????

Thanks for the help guys, if I figure out what is going on I will post back
Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 22nd Apr 2011 02:43
Would you be able to post the "stuck" project. I want to have a look at it.

A clever person solves a problem, a wise person avoids it - Albert Einstein
Bulsatar
15
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 22nd Apr 2011 05:48
Yep, thanks for taking a look at it.
Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 22nd Apr 2011 07:12
Quote: "Yep, thanks for taking a look at it."

No worries. Do you have the .dbpro file that goes with this?

A clever person solves a problem, a wise person avoids it - Albert Einstein
Bulsatar
15
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 22nd Apr 2011 17:30
Um...that isn't all that you need???? That is the only file I have ever saved in the program, is there something else that I should be looking for?

Just to give you guys some perspective, my programming background is in database design and this is the first bit of code that I have tried to create on my own with darkbasic. Trying this as a feeler to get my feet wet with darkbasic and I picked InStr as I am very familiar with how the function is supposed to work.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Apr 2011 20:09
Quote: "Um...that isn't all that you need???? "


Not if the project file is wrong. Post that as well so we can see what you're seeing. The code you posted compiles fine here.
Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 23rd Apr 2011 01:51
Quote: "That is the only file I have ever saved in the program"


I think I know what you have done. Did you just open up the editor, start coding away and when you saved it, you only saved the source file (.dba) without saving the project file? A source file can not compile without a .dbpro file. There are two easy solutions to this.

1: Create a new project by going file-new project and then just copy/paste the source code into the new project.

2: Create a new project and include the source file in that project. You can set it as the main source file if you wish.

Option 1 sounds a lot easier so is probably the best way to go. Just remember, next time you find yourself coding away, to save the project as well as the source code file.

A clever person solves a problem, a wise person avoids it - Albert Einstein
Bulsatar
15
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 23rd Apr 2011 07:31
Yep, that was it I did just open up the editor and start coding. I tried again by opening up a new project and copied the code over and viola! (that is the instrument not the exclamation!) it worked like I wanted it to...well, ok it compiled and then froze because I have a misc loop in a revision I was working on that is infinite, but at least I have a start again.

Thanks a bunch everyone!

Login to post a reply

Server time is: 2026-07-18 06:40:36
Your offset time is: 2026-07-18 06:40:36