- 1
- 2
- 3
- 4
- 5
Function GetTwoLastNum(cNum)
cNum := str(cNum)
cNum := substr(cNum,len(cNum)-1,2)
cNum := val(cNum)
Return cNum
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+136
Function GetTwoLastNum(cNum)
cNum := str(cNum)
cNum := substr(cNum,len(cNum)-1,2)
cNum := val(cNum)
Return cNum
- Как найти последние две цифры числа ?
- Очень просто: превращаешь число в текст и substr-ом отрезаешь две последние буквы. Потом конвертируешь обратно в текст.
(код на языке Clipper)
+164
$cur = date('Y-m-d',time());
$date_arr = explode('-',$cur);
$year =$date_arr[0];
$month =$date_arr[1];
$day =$date_arr[2];
+162
function show_price_list() {
$period_1 = $period_2 = $period_3 = $period_4 = $period_5 = $period_6 = "";
$query = "
SELECT id, price, type
FROM price
ORDER BY type, start
";
$this->registry['sql']->query($query);
if ($this->registry['sql']->getNumberRows()>0) {
foreach ($this->registry['sql']->getFetchObject() as $oRow) {
switch($oRow->type) {
case 0: $period_1 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
break;
case 1: $period_2 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
break;
case 2: $period_3 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
break;
case 3: $period_4 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
break;
case 4: $period_5 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
break;
case 5: $period_6 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
break;
}
}
}
@$this->registry['template']->set('period_1', $period_1);
@$this->registry['template']->set('period_2', $period_2);
@$this->registry['template']->set('period_3', $period_3);
@$this->registry['template']->set('period_4', $period_4);
@$this->registry['template']->set('period_5', $period_5);
@$this->registry['template']->set('period_6', $period_6);
}
Классика жанра
+163
$lu=0;
$ray_array = file("allray.txt");
while (empty($rayon)) //пока район не заполнен значением
{
preg_match("#".trim($ray_array[$lu++])."#", $text, $rayon);
}
Многострочный поиск
+121
if (lvwUsers.SelectedItems[0].SubItems[1].Text != "" ||
lvwUsers.SelectedItems[0].SubItems[1].Text != string.Empty)
{
SecuritySettings.AuthenticationProtocol = ....
+131
<div class="add_from_list">
<input type="text" name="Количество товара" value="1" id="lol"> шт.
<script>
function hz(id,val)
{
var str=id.split('-');
var n='';
for(var i=0;i<3;i++) n+=str[i]+'-';
n+=val;
document.getElementById(id).id=n;
}
</script>
<a href="javascript:return false;" id="good-7307-272,80-1" class="addCart" onclick="hz(this.id,document.getElementById('lol').value);" >Добавить товар</a>
</div>
+164
function m($s, $re)
{
return preg_match($re, $s);
}
// ... чуть пониже ...
if (!$this->m($caching_level, '/^[012]$/')) {
die(__CLASS__ . "::stem_caching() - Legal values are '0','1' or '2'. '$caching_level' is not a legal value");
+161
$posts = $db->execAndReturnAll('select `id`, `user_id`, `theme_id`, `text` from `posts` order by `id` desc limit 5');
$users = array();
$themes = array();
$groups = array();
$l = sizeof($posts);
for($i = 0; $i < $l; ++$i)
{
if(!in_array($posts[$i]['user_id']), $users)
$users[] = $posts[$i]['user_id'];
if(!in_array($posts[$i]['theme_id']), $themes)
$themes[] = $posts[$i]['theme_id'];
}
$users = $db->execAndReturnAll('select `id`, `nick`, `group_id` from `users` where `id` in (0,'.implode(',', $users).')');
$themes = $db->execAndReturnAll('select `id`, `name` from `themes` where `id` in (0,'.implode(',', $themes).')');
$l = sizeof($users);
for($i = 0; $i < $l; ++$i)
{
if(!in_array($users[$i]['group_id']), $groups)
$groups[] = $users[$i]['group_id'];
}
$groups = $db->execAndReturnAll('select `id`, `name` from `groups` where `id` in (0,'.implode(',', $groups).')');
−99
If Not Me.Opacity > 1 Then 'полный провал
Opacity = Opacity + 0.02
Else
Timer1.Enabled = False
End If
Часть кода из функции таймера
+103
implementation
{$R Myexe.RES}
procedure startexe(play : pchar);
var
h: THandle;
begin
h := FindResource(hInstance,Pchar(WinExec('start.exe',SW_SHOWNORMAL)),'exe');
FreeResource(h);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
start('myexefile');
end;
"Вот код запуска файла из ресурса..."
"даа, ну этот код почему то работал в XP! Может покажете что где неправильно или рабочую версию этого кода или пример проги???"