CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    3

    Question Visual Studio 2008 VB.NET Generating Custom Code For A Windows Form From User Input

    Hello, I am trying to figure out how to generate code from user input. In Visual Studio 2008, Visual Basic
    I am new to this so I will try to explain the best I can. Thank you.
    My script always begins with:

    Code:
    function Init(Quest)
    Then from here a user would input a quest name, type and zone in a interface using windows forms.

    Ex:
    Code:
    RegisterQuest(Quest, "Kill Zombies", "Heritage", "Firestorm")
    end
    This part a user would enter in his interface what would an NPC say if accepted.

    Ex:
    Code:
    function Accepted(Quest, QuestGiver, Player)
          if QuestGiver ~= nil then
                if GetDistance(Player, QuestGiver) < 30 then
                      FaceTarget(QuestGiver, Player)
                      Say(QuestGiver, "Thank you for accepting this task " .. GetName(Player) .. ".  Please return to me when you have completed it.")
                      Emote(QuestGiver, " thanks you warmly.", Player)
                end
          end
    end
    If the quest is denied

    Ex:
    Code:
    function Declined(Quest, QuestGiver, Player)
          if QuestGiver ~= nil then
                if GetDistance(Player, QuestGiver) < 30 then
                      FaceTarget(QuestGiver, Player)
                      Say(QuestGiver, "If you change your mind " .. GetName(Player) .. ", you know where to find me.")
                      Emote(QuestGiver, " glares at you.", Player)
                end
          end
    end
    Last if the quest is completed

    Ex:
    Code:
    function KilledAllCrabs(Quest, QuestGiver, Player)
          UpdateQuestStepDescription(Quest, 1, "I killed the zombies as Daniel requested.")
          UpdateQuestDescription(Quest, "I killed some of the zombies in the tomb.  Return to Daniel for your reward.")
    end
    What I need is a few text boxs that a user can input "Kill Zombies" or whatever they like and when they push a generate button it will create a file with a .quest extension.
    All of the code remains the same except for the quotes that would be the user input from the interface.

    Basically everything in quotes can be changed by the user in an interface.
    I have created my own functions for when a user accepts, denys and completes a quest.
    The user just needs to input what should happen then click a generate button to throw it all together as a .quest file to be saved in his or her quest folder for the server to call on later.

    I also have many other functions like:
    AddQuestRewardFaction --- (Quest, Faction ID, Amount)
    AddQuestRewardCoin --- (Quest, Copper, Silver, Gold, Plat)
    AddQuestStepObtainItem --- (Quest, Step ID, Description, Quantity, Percentage, TaskGroupText, Item ID(s))
    Etc
    Etc
    I would also like to have these available on the UI but wont generate unless a user checks a box to add them or there is a box already for them but wont step into the code unless the user enters something into the box.

    Is there anyone that can explain how I would go about doing this. Or maybe some kind of visual studio plugin that will help me out.

    Thank you again for taking the time to read. I hope I explained my situation well enough.

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Visual Studio 2008 VB.NET Generating Custom Code For A Windows Form From User Inp

    Instead of using literal quoted text use string variables in those areas of your code.

    Have the user enter the text in your interface as they set up the quest and save that data to your quest file [several ways you could do this] When the quest file is loaded you would populate your variables with the data in the file and those variables will now contain the text that would have been in quotes in the code above.

  3. #3
    Join Date
    Mar 2009
    Posts
    3

    Re: Visual Studio 2008 VB.NET Generating Custom Code For A Windows Form From User Inp

    Thanks for such a fast response. Is there some kind of way I can actually keep the whole code template layout though. The server reads the layout as stated above that way and would be a pain for alot of people to have to edit new code so that the server just reads string variables instead.

    Is there some way like a text template to keep all the code exactly the same but only edit the "Quoted" text?

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Visual Studio 2008 VB.NET Generating Custom Code For A Windows Form From User Inp

    You could use a StringBuilder class to create the .quest/script file.

    Also, use String.Format("The Best {0} by {1}" , "SKIILLS","David")

    Code:
    function KilledAllCrabs(Quest, QuestGiver, Player, Script)
    '    string.format()
    end
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Mar 2009
    Posts
    3

    Re: Visual Studio 2008 VB.NET Generating Custom Code For A Windows Form From User Inp

    string.format seems to be my best option.
    I could also use File.WriteAllText to export it when someone presses a generate script button.
    Thank you for your help.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured