Jump to content

Yahweh

Members
  • Posts

    186
  • Joined

  • Last visited

Yahweh's Achievements

Member

Member (2/7)

0

Reputation

  1. Yahweh

    Using Random Strings

    Its a lot easier to work with an ArrayList, and a lot more efficient because you only have to loop through the elements of the ArrayList once to generate a random sentence.Here's some code that will do the job:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cArray As New Collections.ArrayList Dim sBuilder As New System.Text.StringBuilder For Each sItem As String In ListBox1.Items cArray.Add(sItem) Next Dim iCounter As Integer, iIterations As Integer Dim myRandom As New Random, iRnd As Integer iIterations = cArray.Count - 1 For iCounter = 0 To iIterations iRnd = myRandom.Next(0, cArray.Count) sBuilder.Append(cArray(iRnd)).Append(" ") cArray.RemoveAt(iRnd) Next Label1.Text = sBuilder.ToString End Sub It works like this:- All the elements from the listbox are shoved into an ArrayList.- The program loops through the ArrayList, selects a random item, appends it to a stringBuilder, then removes that item from the ArrayList.-- Because I'm using an ArrayList, the array indexes are automatically "reset" whenever I remove an item, so there aren't any gaps in list when I remove something from the middle of the list.- After looping through everything, the stringBuilder is printed to screen.
  2. VB6 and Classic ASP use different syntax for opening files. To open a file in ASP, use this code:<%dim fs,f,xset fs=Server.CreateObject("Scripting.FileSystemObject") set f=fs.OpenTextFile(Server.Mappath("aaa.dat"),1,false)x=f.ReadAllf.close Response.Write("The text in the file is: " & x)%>
  3. Yahweh

    SELECT problem

    SELECT d.nameFROM Doctor dLEFT JOIN Patient p ON (d.name = p.name)WHERE d.specialization = p.illness
  4. Yahweh

    Small Asp Error

    Either your database, or the folder where your database is located doesn't have write permissions. CHMOD both of those to drwx------ (700).If you can't CHMOD them, go into IIS and set the file permissions for yourself, or ask your host to do it for you.
  5. Rand() and Limit 5 are specific to MySQL.The equivalent query in SQL server looks like this: That method isn't very efficient if you have 100s of 1000s of records, because it will have to create a NewID() for each record before returning the top 5.To return a single record, there's a little more efficient way:- Get the maximum uniqueID in your table, store that information in a variable called MaximumID- Multiply MaximumID * rnd(), store that information in a variable called RandomID- Select the first record with an ID >= RandomIDIn T-SQL:declare @MaximumID int = Select Max(ID) from table1declare @RandomID int = Rand() * MaximumIDSelect Top 1 * From table1 where ID >= MaximumID Or, you can always do what Microsoft suggests and create a table with random columns already in the table definition.
  6. Officially, it doesn't really matter where you put the code. It can be above all other HTML, after all other HTML, or at any arbitrary point in between. However, as an unwritten rule of thumb, its best to group all of your ASP code into functions at the top of the page to seperate code logic from presentation and prevent excessive spaghetti code. My best advice is this: don't learn Classic ASP. Its a dead language now. Learn ASP.Net because the future of all web development is moving in a .Net direction, .Net is 10000000x more powerful than ASP*, and you'll waste too much time struggling in the future if you don't learn ASP.Net as soon as possible.* Classic ASP is really lacking in many important features, such as being able to generate MD5 hashes, file uploading, and image manipulation; to be able to get any of those functions, you have to write 100s of lines of custom code. ASP.net natively supports all of those functions (and 1000s more) in various namespaces, you can invoke any of those functions in 1 or 2 lines of code. ASP.net also has real datatypes, real page and control events, native support for XML and user memberships, etc.
  7. Yahweh

    sql question

    vit4ek,The error doesn't occur on index.php, because none of the queries on index.php correspond to the error message. The error is located somewhere on one of the include files.I hate to say it, but I don't think anyone is going to be able to help you. Its notoriously difficult to fix problems by copy/pasting an error without seeing the code, its even more difficult to diagnose the error without any line numbers, its even more difficult when 100s of lines of code for an entire page are copy/pasted without formatting or indentation, and its outright impossible to fix errors without seeing the code for right page where the error actually occurs.In spite of all of that, I think I know the cause of the error: There is a column in the table called "Date", but date() is a reserved word in MySQL. MySQL can't tell the difference between a column called date and the date() function; it presumes that the author wanted to use the date() function, but without the parentheses on "date()", MySQL throws a syntax error.To tell MySQL to assume "date" is a column rather than a function, you have to surround the column name by a pair of "`" marks, or write out the fully-qualified name of the column in [table].[column] format, like this:Select * from some_table where `date` + interval 7 day > now();-- alternativelySelect * from some_table t where t.date + interval 7 day > now(); Its up to you to find all the instances of the "date" column appearing without "`" marks and fixing it. Start here and here.
  8. If you need the HTML before processing the ASP, then you can read a text file stored on your server with a FileSystemObject:<%Set fs=Server.CreateObject("Scripting.FileSystemObject")Set f=fs.OpenTextFile(Server.MapPath("some_file.asp"), 1)Response.Write(f.ReadAll)f.CloseSet f=NothingSet fs=Nothing%> If you need the HTML after processing the ASP (I presume that's what you mean by "output source"), then you can read any web page with a an XMLHTTP object: <% Dim objXMLHTTP, xml Set xml = Server.CreateObject("Microsoft.XMLHTTP") xml.Open "GET", "http://www.somewebsite.com/" xml.Send Response.Write xml.responseText Set xml = Nothing%> Rather than response.writinging the data to the screen, you can save it in a variable and work with it some more.
  9. Yahweh

    ASP and XML

    You have to create an XMLDOM object. Learning how to use it is a bit involved, but a good tutorial on reading XML with ASP is available here:http://www.15seconds.com/issue/990527.htm
  10. Step 1: Create a piece of software that crawls pages on the internet.Its probably easiet to create some kind of desktop application to do this. A crawler basically looks at the HTML of a page, indexes the page, extracts all of the URLs, and repeats the process indefinitely. In .Net, you can create a crawler in a few lines of code.Step 2: After creating your crawler, you have to index your data. You can store the data in a database, flat files, or other storage medium. You should choose whether you index the entire page, specific keywords or other information.Step 3: Write server-side backend to execute search queries on your index and display the results.That's the gist of it for a very simple search engine. You can write all of the necessary software for your search engine in less than 400 lines of code (~120 for the crawler and indexer, ~300 for the search page). It won't be any good, but it'll be a genuine search engine.If you don't know how to write desktop software or server-side languages like PHP or ASP.Net, then you won't be able to create a search engine.
  11. ASP Fundamentals:Anything wrapped in the <% ... %> tags is processed server side, that's where all of your form processing takes place. Anything outside is printed to screen, just like a normal HTML document: <%' stuff in this block will be processed by the server%><!-- stuff outside of the block is boring old HTML --> Conditionals in ASP look like this: <% If condition = true then'... do stuffEnd if %> To read form data, use: Request("someFormData") So, putting it all together: <%if Request("frm_toemail") <> "" then ' do all of your form processing here%> Put all of your HTML here.<%else 'abort page%> Put an error message here.<%end if%>
  12. Oops, that should have said:Set Matches = regex.Execute(data) Matches is an object, so you have to use "Set" with it.
  13. Yahweh

    ASP wierdness

    I've had strange experiences with ASP as well: in one case, the code was perfectly fine, but it wouldn't retrive values from the database. I fixed the problem by saving the data into a new file, and mysteriously the identical code would work just fine.For your example, I don't see anything out of the ordinary with the code, unless you've misspelled a variable somewhere (I would imagine that you are like me, and use <% Option Explicit %> at the top of every page). I think the obvious difference between the loop and your code is scope: the loop uses the recordset in global scope, and the variables are assigned from functions which make a reference to your recordset (I assume fromrs and cb_fromrs are functions). You can check if that's the case by assigning your variables directly from your recordset:FORMS_RECORDSET.open("select * from content where cid = '" & fromget("cid") & "'")cid = FORMS_RECORDSET("cid") 'don't need to use fully qualified rs.fields(something).valuetitle = FORMS_RECORDSET("title")description = FORMS_RECORDSET("description")tid = FORMS_RECORDSET("tid")'... That's just my guess, but if that works correctly, then maybe the error in your code is a variable scope issue.
  14. I found a nice article on 4Guys which explains how you can create your own custom control for rollover images.
  15. Odds are, there is some kind of buffer limit, probably 64kb, that you can write to a text file at any given time. If that is the case, then the simple solution to your problem is writing your data is smaller chunks, rather than all at once. You can split your data into fixed-sized chunks using a simple regular expression, then you can write your data chunk by chunk as you loop through the matches collection:Dim regex, match, matches 'regex variablesdim fs, f 'text file vars'creating a text fileset fs=Server.CreateObject("Scripting.FileSystemObject") set f=fs.CreateTextFile(Server.Mappath(someFileName),true) 'create regexp object and set properties set regex = new regexp regex.IgnoreCase = True regex.Global = True regex.Pattern = "[\s\S]{1,10000}" 'matches *at most* 10000 characters at a time 'I'm using "[\s\S]" rather than "." as a convenient way to match newline characters. 'Create matches collection to parse data into managable 10000-character chunks Matches = regex.Execute(data) 'Loop through matches collection for each match in matches 'writing each chunk to the file f.write(Match.Value) nextf.close'cleaning upset regexp = nothingset f=nothingset fs=nothing
×
×
  • Create New...