PDA

View Full Version : [Release v2] Visual Basic Colour coding


John Percival
06-01-2001, 10:00 PM
My first hack for vB :D

In functions.php, add this in at line 425, just after several lines of code about $replacearray

// START VISUAL BASIC PARSING HACK
if (!function_exists("visbasparse")) {
global $kw;
if ($incp) {
include("./visbas.php");
} else {
include("./admin/visbas.php");
}
}
$searcharray[] = "/(\[)(vbcode)(])(\r\n)*(.*)(\[\/vbcode\])/esiU";
$replacearray[] = "visbasparse('\\5')";
// END VISUAL BASIC PARSING HACK


And then upload visbas.php to the admin directory:

<?php
error_reporting(7);
$kw=array("#Const","#If","Abs","Add","Alias","And","Any","AppActivate","Array","As","Asc","Atn","Base","Beep",
"Boolean","Byte","ByVal","CBool","CByte","CCur","CDBl","CDate","CDec","CInt","CLng","CSng","CStr","CVErr","CVar",
"Call","Case","ChDir","ChDrive","Chr","Clear","Close","Collection","Command","Compare","Const","Cos","CreateObject",
"CurDir","Currency","DDB","Date","DateAdd","DateDiff","DatePart","DateSerial","DateValue","Day","Debug","Declare",
"DefBool","DefByte","DefCur","DefDate","DefDbl","DefDec","DefInt","DefLng","DefObj","DefSng","DefStr","DefVar",
"DeleteSetting","Dim","Dir","Do","DoEvents","Double","EOF","Each","Else","ElseIf","End","Endif","Environ","Eqv",
"Erase","Err","Error","Exit","Exp","Explicit","FV","FileAttr","FileCopy","FileDateTime","FileLen","Filelen","Fix",
"For","Format","Function","Get","GetAllSettings","GetAttr","GetObject","GetSetting","Global","GoSub","GoTo","Hex",
"Hour","IIR","IPmt","If","Imp","In","InStr","Input #","Int","Integer","Is","IsArray","IsDate","IsEmpty","IsError",
"IsMissing","IsNull","IsNumeric","IsObject","Item","Kill","LBound","LCase","LOF","LSet","LTrim","Left","Len","Let",
"Lib","Like","Line Input #","Loc","Lock","Log","Long","Loop","MIRR","Me","Mid","Minute","MkDir","Mod","Module",
"Month","MsgBox","NPV","NPer","Name","New","Next","Not","Now","Object","Oct","On","Open","Option","Or","PPmt","PV",
"Pmt","Print","Print #","Private","Property","Public","Put","QBColor","RGB","RSet","RTrim","Raise","Randomize",
"Rate","ReDim","Remove","Reset","Resume","Return","Right","RmDir","Rnd","SLN","SYD","SaveSetting","Second","Seek",
"Select","SendKeys","Set","SetAttr","Sgn","Shell","Sin","Single","Space","Spc","Sqr","Static","Step","Stop","Str",
"StrComp","StrConv","String","Sub","Switch","Tab","Tan","Then","Time","TimeSerial","TimeValue","Timer","To","Trim",
"Type","TypeName","UBound","UCase","Unlock","Until","Val","VarType","Variant","Weekday","Wend","While","Width #",
"With","Write #","Xor","Year",
"Optional","InStrRev","Replace","Split","Join");

function visbasparse($text) {
global $kw;

$text=str_replace("\\'", "'", $text);

$lines=explode("\n",$text);
$val="";
while (list($brr,$line)=each($lines)) {

if (substr(trim($line),0,1)=="'" or strtolower(substr(trim($line),0,4))=="rem ") {
$line="<font color=\"#007F00\">$line</font>";
} else {
$quoteplace=strrpos($line,"'");
if ($quoteplace>0) {
$beforequote=substr($line,0,$quoteplace);
if (countchar($beforequote,"\"")%2==0) {
$afterquote="<font color=\"#007F00\">".substr($line,$quoteplace)."</font>";
$codebit=$beforequote;
} else {
$afterquote="";
$codebit=$line;
}
} else {
$afterquote="";
$codebit=$line;
}

reset ($kw);

$codebit=" $codebit";
while (list($key,$keyword)=each($kw)) {

$codebit=ereg_replace("([\r\n\\(\\)>, .])$keyword([\r\n <,.$\\(\\)])","\\1<font color=\"#00007F\">$keyword</font>\\2",$codebit);

}
$codebit=substr($codebit,1);

if ($afterquote!="") {
$line=$codebit.$afterquote;
} else {
$line=$codebit;
}
}
$val.=$line;
}

$val=str_replace("'", "\'", $val);
$val = str_replace("\\\"","\"",$val);
if (substr($val,0,1)=="\n" or substr($val,0,1)=="\r") {
$val=substr($val,1);
}
return "</normalfont><blockquote><pre><smallfont>visual basic code:</smallfont><hr>" . str_replace("<br>", "", $val) . "<hr></pre><normalfont></blockquote>";

}

?>

Users can then use [vbcode] tags to access this.

I know that this is not very useful for many people, but it could be easily modified for other programming languages.

John

[edit - there's something funny going on with the slashes in the PHP code. Quote this message, and use the code straight from the reply window to get it accurately within any escaping problems.]

ThomasP
06-02-2001, 12:50 PM
Wow, this is amazing!!!

Together with the big amount of "wordfiles" at http://www.ultraedit.com/downloads/additional.html this is very helpful,

Thanks & cheers,
-Tom

filburt1
03-27-2002, 12:20 AM
Anybody know how to install this on vB 2.2.4? I don't see anything about $replacearray on 425, so would somebody please quote a few lines of code I can search for?

filburt1
03-27-2002, 07:53 PM
Um...please? :(

Admin
03-28-2002, 08:31 AM
Add the code John posted right BEFORE this:
} // end version check

Nice hack John! Jelsoft should really hire you to work with them! ;)

filburt1
04-09-2002, 01:54 AM
Cheers, Chen, it worked :) Like John said though, I still had to quote his message and then copy the text. Weird. *shrug*

inetd
04-09-2002, 10:11 AM
please post screenshot of this hack. :)

eiSecure
06-12-2002, 06:46 PM
Originally posted by inetd
please post screenshot of this hack. :) You can see it in action at: http://www.vbforums.com

cybrcyfr
08-09-2002, 04:01 PM
I'm not so good at reg exp... Here you are only replacing if the keyword is found in the exact case it is in the $kw array. How can you change that? We have a ton of developers and they never follow standards.

What would be really nice is if it could find them in ANY case, and format them to the right case (and add color colding).

codebit=ereg_replace("([\r\n\\(\\)>, .])$keyword([\r\n <,.$\\(\\)])","\\1<font color=\"#FF0000\">$keyword</font>\\2",$codebit);

Admin
08-09-2002, 04:06 PM
I haven't looked at the code, but from what you posted I think you will need to replace all calls to "ereg_replace" with calls to "eregi_replace".

DestyNova
08-09-2002, 05:20 PM
wow I m not aware there is hack like this! :thumbup:

John or Firefly

I d like to get some of your hints or tips for this. Since John stated that I can modify this hack to change to C/C++ codes so what and which do you suggest me to change this hack to C/C++? You dont have to do all of that but just tell me which codes that I should change and input C/C++ codes?

thanks

DestyNova
08-09-2002, 07:36 PM
Sorry for double post but I didnt see how.. perhaps 2.2.6 have different lines, I try everything to get it work but no luck. Can anyone give me excat codes to look for to put it above codes to get it work.

DestyNova
08-09-2002, 07:49 PM
Never mind, I got it but still have double line space problem =\

double space problem:

Option Explicit

Dim angle, pi As Integer


Private Sub form_load()

pi = 3.14159

End Sub


Private Sub tmr1_Timer()

'pic1.Cls

If angle <= 359 Then

pic1.Line (278.5, 186.5)-(278.5 + 100 * Math.Sin(angle * (pi / 180)), 186.5 + 100 * Math.Cos(angle * (pi / 180))), vbBlack

angle = angle + 1

End If

'If angle >= 360 Then angle = 0

lbl1.Caption = "Angle = " & angle

End Sub

instead it should be like this:

Option Explicit
Dim angle, pi As Integer

Private Sub form_load()
pi = 3.14159
End Sub

Private Sub tmr1_Timer()
'pic1.Cls
If angle <= 359 Then
pic1.Line (278.5, 186.5)-(278.5 + 100 * Math.Sin(angle * (pi / 180)), 186.5 + 100 * Math.Cos(angle * (pi / 180))), vbBlack
angle = angle + 1
End If
'If angle >= 360 Then angle = 0
lbl1.Caption = "Angle = " & angle
End Sub

So how? I only wish that there is a instruction to help me and anyone to look for excat codes to put after or before instead of based on lucky guess as I did but still getting double space problem. I m going to be king of the bump on this thread until solution come up =P

cybrcyfr
08-09-2002, 08:34 PM
I have actualy noted some highlighting issues...

Even with changing the:
$codebit=ereg_replace("([\r\n\\(\\)>, .])$keyword([\r\n <,.$\\(\\)])","\\1<font color=\"#FF0000\">$keyword</font>\\2",$codebit);

to

$codebit=eregi_replace("([\r\n\\(\\)>, .])$keyword([\r\n <,.$\\(\\)])","\\1<font color=\"#FF0000\">$keyword</font>\\2",$codebit);

See the attached screenshot. I am going t go through and make it case insensative, and allow you to specify CSS colors (and then we can extend it for other languages...)

DestyNova
08-09-2002, 08:38 PM
cybrcyfr

how do you do that without having double space? can you provide which codes to look for to put after or before John's codes? Pls?

thanks

cybrcyfr
08-09-2002, 08:51 PM
I used the code that he posted above. Where are you pulling the code from? I pulled my from the Klient Script Editor. You might have issues with the chr(10) and chr(13) from your source application.

Are you on unix/mac/pc? Unix line breaks are different, I dont think they would carry over though...

Copy your code to notepad, how does it look? Then copy it from notepad into your forums, and see how it looks.

What ver of vB are you using? If you still have issues, pase the code from visbas.php here....

cybrcyfr
08-09-2002, 08:52 PM
I used the code that he posted above. Where are you pulling the code from? I pulled my from the Klient Script Editor. You might have issues with the chr(10) and chr(13) from your source application.

Are you on unix/mac/pc? Unix line breaks are different, I dont think they would carry over though...

Copy your code to notepad, how does it look? Then copy it from notepad into your forums, and see how it looks.

What ver of vB are you using? If you still have issues, pase the code from visbas.php here....

DestyNova
08-09-2002, 09:17 PM
Edit: never mind, I got it work! It is for only UNIX, not PC that s what it does to me so far =P

cybrcyfr
08-09-2002, 09:54 PM
It looks right to me.... I don't know man. :rolleyes:

DestyNova
08-09-2002, 10:04 PM
cybrcyfr

I got it work, it seem work only for UNIX, I use that hack on my local server on my laptop (PC)

Anyway thanks for offer your help =)

Neo
08-09-2002, 10:36 PM
Originally posted by John
My first hack for vB :D

Dont worry John, one day you will be a professional hack just like me!!! :knockedout:

Dev-United
10-30-2002, 02:55 PM
Love your hack John